-
-
Notifications
You must be signed in to change notification settings - Fork 363
Expand file tree
/
Copy pathTestDappNFTs.sol
More file actions
54 lines (45 loc) · 1.55 KB
/
TestDappNFTs.sol
File metadata and controls
54 lines (45 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "@openzeppelin/contracts@4.8.1/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import 'base64-sol/base64.sol';
contract TestDappNfts is ERC721 {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("NFT Token", "NFT") {}
function safeMint(uint256 tokenId) public {
_safeMint(msg.sender, tokenId);
}
function tokenURI(uint tokenId) public pure override returns (string memory) {
string memory svg =
'<svg height="350" width="350" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">'
'<defs>'
'<path id="MyPath" fill="none" stroke="red" '
'd="M10,90 Q90,90 90,45 Q90,10 50,10 Q10,10 10,40 Q10,70 45,70 Q70,70 75,50" />'
'</defs>'
'<text>'
'<textPath href="#MyPath">'
'Quick brown fox jumps over the lazy dog.'
'</textPath>'
'</text>'
'</svg>';
string memory json = string(
abi.encodePacked(
'{"name": "Test Dapp NFTs #',
Strings.toString(tokenId),
'", "description": "Test Dapp NFTs for testing.", "image": "data:image/svg+xml;base64,',
Base64.encode(bytes(svg)),
'", "attributes": [{"trait_type": "Token Id", "value": "',
Strings.toString(tokenId),
'"}]}'
)
);
string memory uri = string(
abi.encodePacked(
"data:application/json;base64,", Base64.encode(bytes(json))
)
);
return uri;
}
}