ERC1155Receiver identity of token being received

Hi all

Not sure if i’m allowed to ask for general development support here but i thought this would be a good place to ask. I have create my own erc1155 token and a contract implementing ERC1155Receiver interface which has the following method signature:

    function onERC1155Received(
    address operator,
    address from,
    uint256 id,
    uint256 value,
    bytes calldata data
)
    external
    returns(bytes4);

There doesn’t seem to be any parameter with the address of the ERC1155 token which means i dont know if i’m receiving an erc1155 of mine, or some other random erc1155. Anyone know how i could identify if the token i’m receiving is one i issued?

Thanks

1 Like

You can identify the token by checking msg.sender, since it’s the token’s safeTransferFrom function the one that calls onERC1155Received on the receiver.

function onERC1155Received(
    address operator,
    address from,
    uint256 id,
    uint256 value,
    bytes calldata data
) external returns (bytes4) {
    require(msg.sender == address(myToken), "Unknown token");
    ...
 }
1 Like