I have 2 contracts, contractA (an ERC721 contract) and contractB (a contract that inherits from IERC721Receiver). I am trying to transfer an nft(contractA) from the owner to contractB.

Originally both contracts had fallback and receive functions. I removed these functions from contract A because I do not need contract A to receive anything. Before removing the receive function from contract A, I was able to call safeTransferFrom on contractA to contractB. After removing the receive function from contractA, this no longer works.

I assumed the flow of this was contractA.safeTransferFrom(tokenOwner, contractB, tokenId, data) -> token transfered to contractB -> contractB.received -> contractB.onERC721Received

It seems that somewhere in this flow contractA.received is being called. Why does the receive method on the contract get called?

1 Answer 1


This is a requisite of IERC721Receiver, in case the transaction reverts.


To clarify, in order to send from contractA, the receiving contract is required to be IERC721Receiver so as to prevent the tokens from becoming locked.

In the process flow, contractA will have safeTransferFrom initiated. Then, it checks to see if the receiving contract is ERC721 compatible. Here are the two outcomes:

A. The check passes, and the tokens are transferred. B. The check fails, and the tx is reverted, sending the tokens back to contractA

…ergo yes, contractA requires at least a receive and/or fallback function to further prevent tokens from being locked.

  • For clarification, contractB has the receive function. ContractA is a standard ERC721 nft contract and does not have the receive function. The nft is being transferred from a user account to contractB. Are you saying that all ERC721 contracts must have receive functions if that nft will be transfered to another contract in the event the receiving contract reverts?
    – Lance
    Commented Dec 21, 2022 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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