I received an interesting question regarding the ERC1155 token, so I decided to share it with you!
Question
Where to enter and read values since my token is already created as you understand. […] So the challenge for me is to understanding where I can enter, one value with one URL as many as I want.
Answer
Each token has its own uri in order to provide more metadata about him. Each time you create a new token, a URI event is emitted:
|
|
In order to check that, you can watch these events and then get their data. For your information, here is an example of a URI event emitted after a token creation:
|
|
As described in the interface, you can find the token id and his linked uri as a _value
.
Or maybe you prefer directly calling the contract with a getUri(idContract)
function. If you want to do so, you can add a getter to your contract, but I would stick to the first solution which is simply listening to the uri events.
From another sight, if you used the same ERC1155 implementation as me (ERC1155Mintable) you should have a setURI
function. If you use it to change the token uri, it will trigger a new URI event that you can then catch in order to read the values.
For easier read, you could deploy a little watching api waiting for these events and store them in a database. I already did it with Go or NodeJS thanks to web3.
I also found a proposal about an ERC1155Metadata_URI interface which makes the read simpler. However, it is still open: https://github.com/ethereum/eips/issues/1155
|
|
Last read option I have in mind would be to read the contract’s past events with web3 like so: https://web3js.readthedocs.io/en/v1.2.9/web3-eth-contract.html#getpastevents
I hope I answered your question. If not, feel free to tell me and I will try again. It’s always a pleasure to help!
Have a great day!