首页 > 解决方案 > 通过另一个第三方合约发送 ERC721 代币

问题描述

我已经创建了一个第三方合约,我想让这个合约能够代表其他地址进行 ERC721 代币转移。我认为做到这一点的唯一方法是从主地址向合约发送已经散列的消息并允许它完成交易。

是否有可能实现我所说的?

pragma solidity ^0.4.24;


import "../../SuperERC721Token.sol";


contract MyContract {

    SuperERC721Token internal externalToken;

    constructor(address address) public {
        externalToken = SuperERC721Token(address);
    }

    function ThirdPartyTransfer(string hashedTRX) public {
        externalToken.call(hashedTRX); // this function allow the contract to send an ERC721 token to another address
    }
}

标签: ethereumsoliditysmartcontracts

解决方案


假设你想functionA从 OtherContract 调用 SuperERC721Token 上的函数,你只需从 SuperERC721Token 中获取接口,ERC20 令牌的接口示例如下:

interface ERC721 /* is ERC165 */ {
    event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
    event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);
    event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
    function balanceOf(address _owner) external view returns (uint256);
    function ownerOf(uint256 _tokenId) external view returns (address);   
    function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
    function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
    function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
    function approve(address _approved, uint256 _tokenId) external payable;
    function setApprovalForAll(address _operator, bool _approved) external;
    function getApproved(uint256 _tokenId) external view returns (address);
    function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}

interface ERC165 {
    function supportsInterface(bytes4 interfaceID) external view returns (bool);
}

interface ERC721TokenReceiver {
    function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external returns(bytes4);
}

在 OtherContract 上,无论您想调用 functionA 的任何位置,都可以输入以下代码:

SuperERC721Token erc721Token= ERC721Token(0x0000000000000000000000000000000000000000); //Replace 0x000000000000000000000000000000000000000 with the address of SuperERC721Token
erc721Token.functionA();

添加任何不在您要调用的接口中的函数。


推荐阅读