1

As per the ERC721 requirements, I have to implement onERC721Recieved. This is how I did it:

function onERC721Received(
    address _operator, 
    address _from, 
    uint256 _tokenId, 
    bytes calldata _data
)external returns(bytes4) {
    return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
} 

This seems to be in line with what is required of the function. However, this raises two questions:

  1. If this does not actually use any of the parameters, why pass the parameters to the function at all? It is now throwing errors every time I test the contract.
  2. What is the reason behind this function?
1

You can remove the errors with this implementation:

function onERC721Received(
    address, 
    address, 
    uint256, 
    bytes calldata
)external returns(bytes4) {
    return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
} 

The parameters are there for implementations that want to use them. Perhaps for doing an accounting of incoming assets. Or perhaps for denying receipt of certain assets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.