forked from p10node/swisstronik-testnet2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PERC721Sample.sol
53 lines (41 loc) · 1.53 KB
/
PERC721Sample.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
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;
import "./ERC721.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "hardhat/console.sol";
contract MyPERC721Token is ERC721, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
uint256 private _nextTokenId = 0;
constructor() ERC721("MyToken", "MTK") {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(MINTER_ROLE, msg.sender);
}
function safeMint(address to) public onlyRole(MINTER_ROLE) {
_safeMint(to, _nextTokenId);
console.log("Mint success", _nextTokenId);
_nextTokenId = _nextTokenId + 1;
}
function supportsInterface(
bytes4 interfaceId
) public view override(ERC721, AccessControl) returns (bool) {
return super.supportsInterface(interfaceId);
}
// disabled logs and signature check in the balanceOf function
function balanceOf(
address account
) public view virtual override returns (uint256) {
if (account == address(0)) {
revert ERC721InvalidOwner(address(0));
}
require(msg.sender == account, "PERC20Sample: msg.sender != account");
return _balances[account];
}
function ownerOf(
uint256 tokenId
) public view virtual override returns (address) {
address owner = _requireOwned(tokenId);
require(msg.sender == owner, "PERC20Sample: msg.sender != owner");
return owner;
}
}