Need help hosting NFTs metadata

erc-721ipfsnft

I am creating a bunch of NFTs using ERC721.

However I see that many other contracts just use centralized hosts to serve their metadata, which means one day these servers will be gone and so will the NFTs…

Eg. Bored Apes collection does it like this:

I wanted to upload the metadata to the IPFS, with the images as well, and it seems there is a service that already does that very easily: https://nft.storage/

However, there is still a problem…

From what I understood, this nft.storage solution still generates URLs like:

ipfs://bafyreib4pff766vhpbxbhjbqqnsh5emeznvujayjj4z2iu533cprgbz23m/metadata.json

Which means I need to store a big URI per NFT in my ERC721 contract (the bafyreib4pff766vhpbxbhjbqqnsh5emeznvujayjj4z2iu533cprgbz23m part).

This will basically kill the project due to the high storage cost/gas fees on the ETH mainnet.

So my question is: Is there a way to generate links that share the same base URI, but then I am allowed to chose the suffix part? Eg. To me this would be the ideal scenario:

  • ipfs://<SAME HASH ON ALL URLs>/tokens/1.json

  • ipfs://<SAME HASH ON ALL URLs>/tokens/1.jpg

  • ipfs://<SAME HASH ON ALL URLs>/tokens/2.json

  • ipfs://<SAME HASH ON ALL URLs>/tokens/2.jpg

Is this possible?

Best Answer

Yes, IPFS support folders. Just pay attention to the CID generation, which is based on the folder content -> once uploaded, the content cannot be changed anymore (without having a new CID).

Feel free to try it for yourself, I just pinned this test folder via Pinata : https://gateway.pinata.cloud/ipfs/QmTcZ21jK22QxPAooVZEr5jFW6u1gpS5REsuVBMZbcNwka