How to get data from token metadata in contract? It is ERC1155 token, metadata json stored on ipfs

1 Answer 1


With ERC-1155 you must know the id of the token, it doesn't matter if that's an ERC-20 Token (Fungible) or an ERC-720 (Non Fungible), you must provide an id.

Assuming for the example that the id is 0 and that the contract you are interacting with supports the optional ERC1155Metadata_URI (You can check that through ERC-165):

You need to call the uri function with your token id 0 which may return one of two things :

  • a specific token uri that you can use right away
  • a generic token uri containing the substring {id} which you will need to replace.

In the second case, with the result after calling contract.uri(0) you should see that {id} substring that you must substitute for your specific id.

As the EIP states :

The string format of the substituted hexadecimal ID MUST be lowercase alphanumeric: [0-9a-f] with no 0x prefix. The string format of the substituted hexadecimal ID MUST be leading zero padded to 64 hex characters length if necessary.

so in our example, you'd need to substitute {id} for : 0000000000000000000000000000000000000000000000000000000000000000.

Additionally, make sure to look for other {id} substring in the resulting json metadata file as it is possible other substitutions are required there too.

If the string {id} exists in any JSON value, it MUST be replaced with the actual token ID, by all client software that follows this standard.

  • Thank you @hroussille but I want use data from metadata in contract that mint this tokens, e.g. function that returns name of token or other information stored in metadata
    – Blendered
    Feb 18, 2022 at 21:29
  • Ah okay, that's not possible straight away http or ipfs are outside of the Blockchain context which is the only one you have access to with solidity. Maybe some oracle service could provide that but I have not heard of it at least...
    – hroussille
    Feb 18, 2022 at 21:51
  • You may extend the contract definition to include your metadata in it or maybe use chain link oracles to fetch those values for you but it goes against the definition of metadata then.. you are not supposed to use them in that context , they are purely informative. Everything you need for logic should be contained in your contract(s)
    – hroussille
    Feb 18, 2022 at 21:55

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.