0

Ive been looking into creating an NFT contract that has a later day/time reveal process. I am trying to figure out how this process works. I am new here so I do apologies if this is too basic.

I have came across a youtube called Hashlips who has a contract on his github that contains this code:

function tokenURI(uint256 _tokenId)
    public
    view
    virtual
    override
    returns (string memory)
  {
    require(
      _exists(_tokenId),
      "ERC721Metadata: URI query for nonexistent token"
    );

    if (revealed == false) {
      return hiddenMetadataUri;
    }

    string memory currentBaseURI = _baseURI();
    return bytes(currentBaseURI).length > 0
        ? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix))
        : "";
  }

This tells me that when tokenURI is called, if the bool revealed is set to false then the NFT will contain the hiddenMetadataUri.

My questions is, if this contract is run at the time of mint and then the nft is sent to the users wallet - How will I be able to update the metadata?

Is, at the time of mint, the NFT JSON and Image "packaged" together and sent to the users address OR everytime the NFT is viewed, will the contract tokenURI be requested for the updated url?

Again I am sorry if this is very basic, I have googled and even tried the AI chat but can't get a clear answer (probably my search terms) - I would really appreciate detailed answers/links to resources where I can figure this out.

1 Answer 1

0

Gm Sir.

My questions is, if this contract is run at the time of mint and then the nft is sent to the users wallet - How will I be able to update the metadata?

I believe that since the state of deployed contract is visible for everyone, it is a necessary to override the ipfs link after contract deployment in appropriate moment (reveal moment). But there is other potential solution.

Ipfs service pinata introduced a solution called Submarining. The idea of Submarining is to make files private until you decide to make them public for everyone. You could use it to store both pre-reveal and post-reveal ipfs links in your contract, if you have a need to automatically switch between these two links under some circumstances, and later you'll just need to make your files public when it is time.

https://www.pinata.cloud/blog/introducing-submarining-what-it-is-why-you-need-it

Personally I prefer the first solution with ipfs link update. You can handle it by creating a function in your smart contract to override the ipfs link that is stored. Remember to make this function callable only for contract owner, otherwise you'll get rekt. Here's a code example below:

 function setBaseURI(string memory _NewBaseURI)
    public 
    onlyOwner
    {
        baseURI = _NewBaseURI;
    }

You'll be later able to update the ipfs link directly via etherscan:

Is, at the time of mint, the NFT JSON and Image "packaged" together and sent to the users address OR everytime the NFT is viewed, will the contract tokenURI be requested for the updated url?

Services like OpenSea are reading the properties of NFT directly from the contract (this is possible because of the ERC-721 and NFT's metadata standards). I don't know if they are reading it everytime when NFT is viewed, but certainly they are using this approach with reading contract.

I hope this helps Sir, feel free to ask if you have any more questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.