Why doesn't OpenZeppelin ERC721 contain setTokenURI?

Yes, we think most people should try to avoid setTokenURI if possible for their use case.

If you use IFPS, your baseURI wouldn’t be gateway.pinata.cloud, it would be the URI to an IPFS directory.

For example, I just uploaded a directory to Pinata at https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/.

I can now create an ERC721 with that URL as its baseURI (or I could use a native ipfs:// protocol URI), and mint token IDs 1 and 2.

The concatenated URI for token ID 1 would then be https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/1, and you will find the metadata there.

For NFTs where new tokens are minted dynamically, it would be possible to use IPNS to update the base URI to point to an updated directory of metadata.

It’s always possible to use ERC721URIStorage with setTokenURI if this doesn’t work or someone finds it too complicated to set up.

4 Likes