我已经创建了第三方合同,我希望使该合同能够代表其他地址进行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
}
}
答案 0 :(得分:0)
假设您要从OtherContract调用SuperERC721Token上的functionA
函数,您所要做的就是从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();
添加您要调用的界面中没有的任何功能。