How to use the ERC1155Holder

Hello community.

For a contract to be able to receive and manage 1155 NFTs you inform us that we must implement the ERC1155Holder contract.

But I am confused about its implementation as you say in the guide:

When we want to send a NFT we have to call the onERC1155Received function and not use the SafeTransferFrom?

The values parameter of onERC1155Received represents the amount?

then it says to return the following bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)") (i.e. 0xf23a6e61, or its own function selector). after generating the transfer.

It is also commented that this function onERC1155Received at the end of a safeTransferFrom must be called after the balance has been updated.

It all seems a bit confusing to me and I wonder if you have implemented a contract that can receive and send ERC1155 NFTs as an example model.

ERC1155Holder only enables a contract to receive tokens. You just have to inherit from this contract, and the contract will be able to receive ERC-1155 tokens.

But you will also probably need to add some way to transfer the tokens out of there. This is separate. You just have to invoke safeTransferFrom to do that.

You mean create an interface of ERC1155 contract and invoke the safeTransferfrom function in order to get the tokens out?
As if it were a common marketplace?

Yes I think it's as you're describing.

For me you are a source of truth.
Thank you.

1 Like