ERC1155 Modifying token metadata

Hello, I’m new to the blockchain space and am trying to make a dApp with a team.

Currently, we want to make an ERC1155 token that adds the ‘_from’ address to some external database as well as the coin as metadata when ‘safeTransferFrom’ function is called.

So we copy pasted the IERC1155 implementation from here and are directly modifying ‘safeTransferFrom’ as well as the ‘safeBatchTransferFrom’ functions from IERC1155 so we can modify the metadata of the token.

Currently, we haven’t made any modifications but are running into some errors, and are wondering if we could do the same thing by creating a function that calls ‘safeTransferFrom’ or ‘safeBatchTransferFrom’, then if the transfer goes through, add the metadata to some database as well as modify the coin itself.

However we weren’t able to find any functions that would explicitly allow us to modify the metadata of the token, so we feel like we directly need to modify the functions in IERC1155.

How do we modify the metadata of tokens being transferred in ERC1155?

1 Like

Hi @VadneyK,

Welcome to the community :wave:.

If using the token URI scheme with clients replacing {id} then there isn’t a need to change onchain.

I assume that updating the database and modifying the metadata can all happen off chain.

You could listen for the TransferSingle event and then add your data to an external database and update the metadata.

OpenZeppelin Contracts has an ERC1155 implementation that you could extend.

There is also a Preset ERC1155 contract that you could experiment with.

I have created a simple example: Create an ERC1155

Functionality needs to conform to the EIP for it to be an ERC1155 token, so you couldn’t change the interface.

Thank you for the response!

We want to keep the transaction history of the coin on-chain so that no one can tamper with what accounts used to have the account. We want to use a token to create a tamper-proof history of where the token has been.

Is there any way to edit the metadata of the coin every time the coin is transacted?

1 Like

Hi @VadneyK,

To get a transaction history you can get this from the emitted events TransferSingle and TransferBatch. These should be emitted for all minting, transferring and burning.
See the EIP for details:

For details on events see the Solidity documentation:

Is that what you were after?