How to use third party contract to send ERC token?

0 votes

I want to send ERC721 tokens using a third-party contract that I have and I trying to do it with the following code but I know it’s not right. How to do it?

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

    }

}
Aug 10, 2018 in Blockchain by digger
• 26,600 points
42 views

1 answer to this question.

0 votes

You can do it by using a code similar to the example mentioned below:

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);

}

And in the contract that you want to call functionA, you add this code:


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

erc721Token.functionA();
answered Aug 10, 2018 by slayer
• 29,240 points

Related Questions In Blockchain

0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,090 points
492 views
+1 vote
1 answer

How to write an ERC 721 contract?

You could go through the following links:  https://github. ...READ MORE

answered Jun 28, 2018 in Blockchain by Perry
• 17,090 points
517 views
0 votes
1 answer

How to use real world/live data in my smart contract?

You cant access/embed real world data using ...READ MORE

answered Jul 12, 2018 in Blockchain by digger
• 26,600 points
65 views
0 votes
1 answer

How to send ethers to a contract?

Transfer of tokens means you will deduct ...READ MORE

answered Jul 25, 2018 in Blockchain by charlie_brown
• 7,720 points
53 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,810 points
186 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,600 points
5,151 views
0 votes
1 answer

How to store photos in Hyperledger smart contract?

To do this, you need to represent ...READ MORE

answered Jul 9, 2018 in Blockchain by slayer
• 29,240 points
82 views