1

Im currently onto developing my own NFT. It will be only one NFT in the contract with the ID "0".

First of all, do you see problems in adding the URI to the NFT after minting it (it has to do with the use behind it)?

Second: What would be the best approach to link the NFT in the IPFS. Should it be linked through a directory or directly (ipfs/directory-hash/token-id or ipfs/file-hash)

As I see the latest OpenZeppelin-Standard implies two Attributes: The Base-URI which is initial, and the tokenURI. Now should the Base-URI in that case be "ipfs/" or in the other case the "directory-hash". Or should the Base-URI be just ipfs/ and the token URI the hashed file without the directory.

Another possibility would be that the Base URI would be the gateway to access the file, but I would rather put the gateway on the Webapp.

I would really appreciate to hear some opinions and best practices :)

1 Answer 1

5

The best practice to store metadata in IPFS would be the following:

  1. Upload your metadata JSON files to a IPFS directory and get the its CID. The name of the files should be like <tokenId>.json
  2. Add the CID to the smart contract as a baseURI like ipfs://<CID>/
  3. Now, when querying the tokenURI, the function should return ipfs://<CID>/<tokenId>.json

Initial NFT drops may have bugs, so the best practice is to have the ability to change the baseURI and lock it once all data is final and correct. This will prevent you from redeploying the contract in case of any mistake in the JSON files. Also, keep in mind you will not be able to edit any files in your IPFS folder after deployment.

4
  • Exactly what I was looking for, thank you for your tips :)
    – Luex
    Nov 5, 2021 at 14:20
  • great ! you can also refer the freeze URI event in-case you wish to show that you're base URI is permanent on opensea. docs.opensea.io/docs/metadata-standards Nov 5, 2021 at 15:52
  • @Sujith Somraaj How do you add the ".json" after tokenId? Did you override the tokenURI function by yourself? Since I check some of the reference on ERC-721A contract, they are using _baseUrl() function only. ref: etherscan.io/address/…
    – tcf01
    Feb 28, 2022 at 17:53
  • Another trick if you want to be able to avoid having to override tokenURI method in your contract (so you can skip appending the .json extension) is to edit your metadata filenames in terminal so they match the token id. For example the metadata file for token #1 will simple be named "1" (without quotes obviously).
    – dmulvi
    May 30, 2022 at 1:44

Your Answer

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

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