用ether.js 调用 safeTransferFrom 方法时总是报 safeTransferFrom is not a function 错误
function safeTransferFrom(
address from,
address to,
uint256 id
) public virtual {
transferFrom(from, to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(
msg.sender,
from,
id,
""
) ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function safeTransferFrom(
address from,
address to,
uint256 id,
bytes calldata data
) public virtual {
transferFrom(from, to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(
msg.sender,
from,
id,
data
) ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
在ERC721中 safeTransferFrom 是重载方法 单独根据方法名去找 就会找到两个 。
也就是contract.safeTransferFrom(…) 这种写法是有问题的。
错误写法
contract.safeTransferFrom(addr1, addr2, 1);
正确写法
contract["safeTransferFrom(address,address,uint256)"](addr1, addr2, 1);
网友评论