-
Notifications
You must be signed in to change notification settings - Fork 4
/
WebSiteToken.sol
44 lines (32 loc) · 1.12 KB
/
WebSiteToken.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "MyERC721.sol";
contract WebSiteToken is ERC721 {
mapping(uint256 => string) values;
mapping(string => uint256) uriMap;
uint256 totalSupply;
constructor() ERC721("WebSiteToken", "WST") public {
totalSupply = 0;
mint(msg.sender, "google.com");
mint(msg.sender, "naver.com");
mint(msg.sender, "facebook.com");
}
function mint(address to, string memory uri) public {
require(uriMap[uri] == 0);
uint256 newTokenId = totalSupply + 1;
_mint(to, newTokenId);
values[newTokenId] = uri;
uriMap[uri] = newTokenId;
totalSupply = totalSupply + 1;
}
function getUri(uint256 tokenId) public view returns (string memory) {
return values[tokenId];
}
function getTokenIdByUri(string memory uri) public view returns (uint256) {
return uriMap[uri];
}
function whoHasUri(string memory uri) public view returns (address) {
uint256 tokenId = getTokenIdByUri(uri);
return ownerOf(tokenId);
}
}