I am making an contract that allows for unlimited minting of NFTs (they will be for identification purposes, not necessarily collecting). But since the number of NFTs, and therefore corresponding metadata files, will be nondeterministic, it does not seem possible to set the URI to a single ipfs:// address at time of launch.

Some solutions I was considering are:

  • Creating a mapping for token => CID which gets updated as part of the minting function. Client logic would be in charge of fetching and providing the CID. But it seems wasteful to store all those strings.
  • Using a hosted IPFS gateway. Lots of NFTs do this right now, but it seems to defeat the purpose of using IPFS in the first place since I can change the pointers if it's my own gateway.

Has anyone tackled this problem before? Any help appreciated.

1 Answer 1


You could use IPNS to have dynamic URI ending with an ID. Usually in the NFT contract the tokenURI function is implemented like this:

function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
  • 1
    IPNS (or the related DNSLink) looks like the right solution - I will come back and mark it as the answer if I can get it working
    – Alex Otsu
    Oct 19, 2021 at 16:31

Your Answer

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

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