请问如何合约接受NFT质押,按论坛里的方法暂时没找到可行的案例

账号A先在ERC721中对合约地址ApproveAll,然后账号A调用函数some(合约地址,某个nftID)

contract Town is IERC721Receiver,ERC165{
    constructor(){}

    function some(address nft,uint256 _tokenId) public {
      IERC721(nft).transferFrom(msg.sender,address(this), _tokenId);
    }

    function onERC721Received(
      address,
      address from,
      uint256,
      bytes calldata
    ) external pure override returns (bytes4) {
      require(from == address(0x0), "Cannot send tokens to Barn directly");
      return IERC721Receiver.onERC721Received.selector;
    }
}

错误提示为“

Reason provided by the contract: "ERC721: transfer caller is not owner nor approved"
```”

谢谢大哥们解答

请先 登录 后评论

1 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 1 关注
  • 0 收藏,2315 浏览
  • 南枳 提出于 2022-06-29 00:22