Skip to content

Instantly share code, notes, and snippets.

@Rahat-ch
Created April 7, 2022 12:17
Show Gist options
  • Select an option

  • Save Rahat-ch/1fcddce55f02519d23b2f405f60c0a6f to your computer and use it in GitHub Desktop.

Select an option

Save Rahat-ch/1fcddce55f02519d23b2f405f60c0a6f to your computer and use it in GitHub Desktop.

Revisions

  1. Rahat-ch created this gist Apr 7, 2022.
    29 changes: 29 additions & 0 deletions MetaDataNFT.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    // 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;
    }
    }