Created
April 7, 2022 12:17
-
-
Save Rahat-ch/1fcddce55f02519d23b2f405f60c0a6f to your computer and use it in GitHub Desktop.
ERC721 minting with timed slowdown
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 | |
| pragma solidity ^0.8.0; | |
| import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
| import "@openzeppelin/contracts/utils/Counters.sol"; | |
| contract MetaDataNFT is ERC721URIStorage { | |
| using Counters for Counters.Counter; | |
| Counters.Counter private _tokenIds; | |
| mapping (address => uint256) public mintTracker; | |
| constructor() ERC721("MetaDataNFTV2", "MDNFT2") {} | |
| function mint(string memory tokenURI) public returns (uint256){ | |
| if(mintTracker[msg.sender] > 0){ | |
| require(block.timestamp >= mintTracker[msg.sender], "Please wait 24 hours before minting again"); | |
| } | |
| uint256 slowdown = block.timestamp + 1 days; | |
| _tokenIds.increment(); | |
| uint256 newItemId = _tokenIds.current(); | |
| _safeMint(msg.sender, newItemId); | |
| _setTokenURI(newItemId, tokenURI); | |
| mintTracker[msg.sender] = slowdown; | |
| return newItemId; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For line 16, I think you can change this:
To just:
Because for new accounts,
mintTracker[msg.sender]would be less thanblock.timestampanyways, because it would be zero while block's timestamp is non-zero positive.