Created
April 20, 2024 14:20
-
-
Save hashcott/cfc2d1669965a7d05eecd601aec94798 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| // Compatible with OpenZeppelin Contracts ^5.0.0 | |
| pragma solidity ^0.8.20; | |
| import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
| import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
| import "@openzeppelin/contracts/access/Ownable.sol"; | |
| // collection => OWNER | |
| contract RonaldoNFT is ERC721, ERC721URIStorage, Ownable { | |
| uint256 public _nextIdToken = 0; | |
| mapping (address => bool) public whitelist; | |
| constructor(address initialOwner) | |
| ERC721("MyToken", "MTK") | |
| Ownable(initialOwner) | |
| {} | |
| // function _baseURI() internal pure override returns (string memory) { | |
| // return "https://drive.hashcott.me"; | |
| // } | |
| // https://drive.hashcott.me/ronaldo.png => url | |
| // | |
| function createWL(address _player) public onlyOwner { | |
| whitelist[_player] = true; | |
| } | |
| modifier onlyWhiteList { | |
| require(whitelist[msg.sender] == true); | |
| _; | |
| } | |
| function safeMint(address to, string memory uri) public onlyPlayer { | |
| // duy nga doc ton | |
| uint256 id = _nextIdToken++; | |
| _safeMint(to, id); | |
| // uri = https://drive.hashcott.me/ronaldo.png | |
| _setTokenURI(id, uri); | |
| } | |
| // The following functions are overrides required by Solidity. | |
| // id 1 => ronaldo-smile.png | |
| function tokenURI(uint256 tokenId) | |
| public | |
| view | |
| override(ERC721, ERC721URIStorage) | |
| returns (string memory) | |
| { | |
| return super.tokenURI(tokenId); | |
| } | |
| function supportsInterface(bytes4 interfaceId) | |
| public | |
| view | |
| override(ERC721, ERC721URIStorage) | |
| returns (bool) | |
| { | |
| return super.supportsInterface(interfaceId); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment