How to: ERC-1155 ID Substitution for Token URI

great its really help me. thank so much

Actually, since the openzeppelin URI function is virtual, you can override it to change the URI each time you mint tokens. See https://medium.com/coinsbench/fully-decentralized-erc-721-and-erc-1155-nfts-6c229adf9c9b

contract MyNFT_ERC1155 is ERC1155 {
    mapping (uint256 => string) private _tokenURIs;

    constructor() ERC1155("Anything_you_want") {} 

    function uri(uint256 tokenId) override public view 
    returns (string memory) { 
        return(_tokenURIs[tokenId]); 
    } 
    function _setTokenUri(uint256 tokenId, string memory tokenURI)
    private {
         _tokenURIs[tokenId] = tokenURI; 
    } 
}
2 Likes

We have a simple implementation of this idea in in python documented here: https://core.iscc.codes/utilities/utils/#iscc_core.utils.cidv1_hex ...
See functions:

cidv1_hex()
cidv1_to_token_id()
cidv1_from_token_id()

maybe that helps.

I have a similar question around ID substitution.

The standard implies that the {id} MUST be replaced in all attributes within the metadata JSON. In practice I am not seeing this. Does anyone have any experience with this?

I have implemented the example where v1 CID uri implemented

1 Like