ERC-721 – How to Link IPFS

erc-721ipfs

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 🙂

Best Answer

So regarding NFTs, the best practice would be able to have the following:

  1. Upload your Metadata info to a folder in IPFS and get the CID of the directory. the name of the file should be like <tokenId>.json
  2. Add the CID to the smart contract as a base URI like ipfs://<CID>
  3. Now during query to tokenURI function return ipfs://<CID>/<tokenId>.json

Now also make sure initial NFT drops may have bugs, so the best practice is to have the ability to change these baseURI and lock it once all data is final and are correct.

This will prevent you from redeploying the contract in case of any mistake in JSON. Also, you cannot edit any files in your IPFS folder after deployment.

Related Topic