ERC1155 data parameter on mint method

I’m using ERC1155 based on ERC1155PresetMinterPauser. I Didn’t change anything from that implementation

How does mint function actually uses “data” argument? is that mandatory?, if yes ,why? what that “data” actually represents?

I see no references to that on mint function, or in _mint internal function, not even in the events emited during minting, notexplanation on comments… maybe I’m losing something, I just don’t understand what should we do with “data” here

1 Like

Hi @rtraba,

The preset contract doesn’t use the data parameter but passes it on. If you needed to pass additional data for mint and transfers then you could use data.

EIP-1155 safeTransferFrom describes the data parameter as follows:

Additional data with no specified format, MUST be sent unaltered in call to onERC1155Received on _to

_mint just passes data without any modification:

1 Like

Thanks abcaoathup, so I see that basically _data parameter is just there to keep compliance with the standard most of all.
Can you provide some insight about why the standard enforce this? I mean the reasons why. I understand that a any particular deployment could overwrite this method and do something with that data, maybe as a way of using a tag for some minting transactions and just emitting enriched data events or something else… I mean, there is no enforced _data argument on erc20 or erc721 for e.g., this makes for example that any wallet or dapp or third party contract that will mint on erc1155 should be aware of adding void arguments when calling this function. Just like you do in GameItems contract constructing_an_erc1155_token_contract

_mint(msg.sender, GOLD, 10**18, "");
_mint(msg.sender, SILVER, 10**27, "");
_mint(msg.sender, THORS_HAMMER, 1, "");
_mint(msg.sender, SWORD, 10**9, "");
_mint(msg.sender, SHIELD, 10**9, "");

So, maybe what I’m asking is some useful example that actually takes some advantages of this “extra” parameter. Thanks again

1 Like

Hi @rtraba,

To find more information about the _data parameter I suggest reading through the EIP:

The issue comments are a great source of information about why an EIP has specific functionality. See the following comment:

I don’t know which ERC1155 tokens use _data.


As an aside, I created a simple ERC1155 example: Create an ERC1155

Feel free to ask questions and I can improve the example.