The _checkOnERC721Received internal function

The _checkOnERC721Received() function is an internal function that is responsible for further calling the onERC721Received() function on an ERC721Receiver contract. Here, the ERC721 contract is behaving like a proxy to the ERC721Receiver contract. If the recipient is not a contract account, the function simply returns true.

The function takes the following arguments:

  • from: The address of the current owner of the NFT
  • to: The address of the recipient of the NFT
  • tokenId: The tokenId of the NFT that is to be transferred

Let's look at the _checkOnERC721Received() function definition:

function _checkOnERC721Received(address from, address to, uint256 tokenId, 
bytes memory _data)
internal returns (bool)
{
if (!to.isContract()) {
return true;
}

bytes4 retval = IERC721Receiver(to).onERC721Received(msg.sender,
from, tokenId, _data);
return (retval == _ERC721_RECEIVED);
}

As you can see in the preceding code, when the to address (the recipient's address) is not a contract address, the function returns true. However, if the to address is a contract, it further calls the onERC721Received() function on the contract. As per the ERC721Receiver contract, the call to the onERC721Received() function should return the bytes4 function signature that represents the onERC721Received() function signature. The function signature is stored in the _ERC721_RECEIVED constant. If a recipient contract does not have onERC721Received() function defined, the transaction would fail.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.203.215