Linking IPFS in ERC-721

Hello guys,

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 :smile:

If the contract is going to be a single NFT, I guess it doesn't make a difference whether you use a directory or just a file link.

If you want to use a file link, you don't need to set the base URI (which is useful for directories), you can just leave it empty.

I don't think this would cause issues. Maybe if you load it on a site like OpenSea they're going to cache the metadata, and if you update it later you would have to flush their cache somehow.

1 Like

I know it has been a while. But I just came back to this topic and Im now questioning myself if I should not rather use the baseURI to directly link the token in IPFS. Setting the tokenURI in the ERC-721 standard manually seems not intended. For the baseURI I can just paste it in the quotation marks :slight_smile:

Not sure I understand the question sorry.

Well, I have created an IPFS folder with the CID abc. I now set the BaseURI of my ERC721 as "ipfs://abc/". The file where data is stored should now have the same name as the tokenURI for example 0.json. So when I call ERC721.tokenURI(0) it will return "ipfs://abc/0". The problem is that I need it to return "ipfs://abc/0.json" don't I? How can I achieve that.

Ah yes. The base URI mechanism out of the box won't help you with that. You can name your files 0 instead if 0.json, it should work. If you want the .json extension you could override the tokenURI implementation to concatenate .json at the end.

1 Like