Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Question RE: ERC1155_BATCH_RECEIVED_VALUE #60

Open
curldapps opened this issue Sep 23, 2020 · 1 comment
Open

General Question RE: ERC1155_BATCH_RECEIVED_VALUE #60

curldapps opened this issue Sep 23, 2020 · 1 comment

Comments

@curldapps
Copy link

Apologies in advance for the general question in the issues section, but I felt it is a simple enough query to not be a bother.

I wanted to get some help understanding the happy path for the contract recipient check during mint functions:

function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, uint256 _gasLimit, bytes memory _data) internal { // Pass data if recipient is contract if (_to.isContract()) { bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived{gas: _gasLimit}(msg.sender, _from, _ids, _amounts, _data); require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE"); } }

I am not certain what input in bytes during mint and batchMint would allow me to distribute tokens to a contract address. I do not fully understand how this check works. I can see the set values in the ERC1155.sol contract state variables, but do not know what needs to be input in arguments for an actual mint to pass this check.

Any help would be appreciated :) I am 90% done with an implementation of ERC1155 that borrows from this repository's fantastic framework. Thank you in advance.

@curldapps
Copy link
Author

After a bit of tinkering I believe I have solved my own query, but want to leave this open for confirmation at your leisure. :)

I was tripped up because I forgot the small detail that the onERC1155Received() function uses abi.encodePacked() which returns unpadded bytes. So when implementing this method in the receiving contract, I was using the magic value input (default "Hello from the other side") and trying to pass the padded bytes32 representation of that in _data. Hence, none of the contracts, including ERC1155ReceiverMock with the function implemented were working without reverting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant