How to have custom uri for each token type in ERC1155

The ERC1155 standard recommends using a single URL as the base metadata URL. And the clients need to replace {id} in the URL to get the desired metadata for a particular tokenType with its id.
Is there a way to have a separate URL for each token so that we can use IPFS to store the metadata without the need for a centralized metadata server (even if that's redirecting to an IPFS hash).

ERC1155 with {id} doesn't require a centralized metadata server. See this discussion about baseURI in ERC721:

If you still want to have a separate URL for each token, you would need to extend our ERC1155 implementation and override the uri(uint256 id) function to make it return your custom URL. Potentially you can read from a mapping indexed by id. Something similar to what ERC721URIStorage does.

The base URL is basically the "folder". Every URI appended after that is fully separate and there's no need for a centralized host for 'em.

We habitually use IPFS for this and nothing about it is centralized. For example,
BaseURI being ipfs://QmAbCD... and three token URIs being ipfs://QmAbCD.../foo.tiff, ipfs://QmAbCD.../bar.tiff and ipfs://QmAbCD.../foobar.tiff

1 Like