0

What is the process called when using e.g a token smart contract in an ICO smart contract? and could someone provide an explanation of the process. I'm not sure that I understand how interaction between multiple contracts works. Thank you very much.

1 Answer 1

0

In order to interact with other contract from your own, you need to have some sort of interface, for example interface for standard ERC20 token would look something like this:

contract ERC20_Token{
      function balanceOf(address _owner) constant returns (uint256 balance);
      function transfer(address _to, uint256 _value) returns (bool success);
      function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
      function approve(address _spender, uint256 _value) returns (bool success);
      function allowance(address _owner, address _spender) constant returns (uint256 remaining);
      event Transfer(address indexed _from, address indexed _to, uint256 _value);
      event Approval(address indexed _owner, address indexed _spender, uint256 _value);
      uint public decimals;
      string public name;
}

Then you can call functions on other contract using this interface, you just need to provide address of contract that you are planning to use.

For example:

ERC20_Token("address of token contract").transfer("address","value");

Basically you can map all functions you want to use in the interface contract, for example if you just want to use transfer function you don't need to include all ERC20 standard functions. Note that your request will be coming from your contract and not your address you called contract from, so to transfer tokens you would need that token to be available on your contract address.

3
  • Hi, How would it look like to make token available ?
    – NowsyMe
    Commented Jan 17, 2018 at 1:53
  • Hi, i am not sure i fully understand your question. In this example Token you want to access should be already deployed as separate contract, and this ERC20_Token contract used in this example is just an interface, you can put in alongside your other contract code you want to use it with.
    – TracerWimp
    Commented Jan 18, 2018 at 3:52
  • It will allow you to call it like i showed above, just pass address of contract you want to call in ERC20_Token(<here>), and you will be able to call all functions that ERC20_Token interface have, but instead of blank function you have in your interface it will make call to actual contract on that address.
    – TracerWimp
    Commented Jan 18, 2018 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.