Skip to content

Instantly share code, notes, and snippets.

@shobhitic
Last active June 8, 2023 03:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shobhitic/ad0f824ee488481c70a0d0edbb181dc1 to your computer and use it in GitHub Desktop.
Save shobhitic/ad0f824ee488481c70a0d0edbb181dc1 to your computer and use it in GitHub Desktop.
Contract to help with Pre reveal metadata for NFT smart contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts@4.8.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.8.0/access/Ownable.sol";
import "@openzeppelin/contracts@4.8.0/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