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 55 56 57 58 59 60 61 62 63 64
| // SPDX-License-Identifier: MIT pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Royalty.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/Counters.sol";
contract MyToken is ERC721, ERC721Royalty, ERC721URIStorage, Ownable {
error OwnerError(string errorMsg,address owner,uint256 tokenId);
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("MyToken", "MTK") {}
function _baseURI() internal pure override returns (string memory) { return "https://thinkingchain.app/"; }
function safeMint(address to, string memory uri) public onlyOwner { uint256 tokenId = _tokenIdCounter.current(); _tokenIdCounter.increment(); _safeMint(to, tokenId); _setTokenURI(tokenId, uri); }
// The following functions are overrides required by Solidity. function _burn(uint256 tokenId) internal override(ERC721,ERC721Royalty, ERC721URIStorage) { super._burn(tokenId); }
function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) { return super.tokenURI(tokenId); }
// 设置默认的版权税 function setDefaultRoyalty(address receiver, uint96 feeNumerator) public onlyOwner { _setDefaultRoyalty(receiver,feeNumerator); }
// 个人设置NFT版权税 function setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) public { address owner = ownerOf(tokenId); if(owner != msg.sender){ revert OwnerError("Not owner",owner,tokenId); } _setTokenRoyalty(tokenId,receiver,feeNumerator); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC721Royalty) returns (bool) { return super.supportsInterface(interfaceId); }
}
|