function _checkOnERC721Received(
address from,
address to,
uint tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
return
IERC721Receiver(to).onERC721Received(
msg.sender,
from,
tokenId,
_data
) == IERC721Receiver.onERC721Received.selector;
} else {
return true;
}
}
这一段其实是721对收币地址的一个判断,如果地址是账户,则直接转账,是合约的话则会判断,该合约是否有引用IERC721Receiver这个接口,并返回onERC721Received.selector。没有的话,会进行一个回滚。
所以我们的合约应该这样写
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;
interface ERC721TokenReceiver {
/// @notice Handle the receipt of an NFT
/// @dev The ERC721 smart contract calls this function on the recipient
/// after a `transfe