Last active
June 8, 2023 03:05
-
-
Save shobhitic/ad0f824ee488481c70a0d0edbb181dc1 to your computer and use it in GitHub Desktop.
Contract to help with Pre reveal metadata for NFT smart contract
This file contains 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.9; | |
import "@openzeppelin/[email protected]/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/[email protected]/access/Ownable.sol"; | |
import "@openzeppelin/[email protected]/utils/Counters.sol"; | |
contract PreRevealedTokens is ERC721, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIdCounter; | |
bool public isRevealed = false; | |
string preRevealedURI = "https://www.jsonkeeper.com/b/S00G"; | |
string baseURI = ""; | |
constructor() ERC721("PreRevealedTokens", "PRT") {} | |
function _baseURI() internal view override returns (string memory) { | |
return baseURI; | |
} | |
function safeMint(address to) public onlyOwner { | |
uint256 tokenId = _tokenIdCounter.current(); | |
_tokenIdCounter.increment(); | |
_safeMint(to, tokenId); | |
} | |
function tokenURI(uint256 tokenId) | |
public | |
view virtual | |
override | |
returns (string memory) { | |
if (isRevealed) { | |
return super.tokenURI(tokenId); | |
} | |
return preRevealedURI; | |
} | |
function setPreRevealedURI(string memory _preRevealedURI) | |
external onlyOwner { | |
preRevealedURI = _preRevealedURI; | |
} | |
function revealAndSetBaseURI(string memory baseURI_) | |
external onlyOwner { | |
isRevealed = true; | |
baseURI = baseURI_; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment