6


I have two smart contracts,
the first which i intend to deploy first then after a couple of days the other will follow. my issue is how to import this contract i have already deployed and use its functions in my contract.
i have tried Coin1 _coin1 = Coin1(addressOfCoin1);
but it doesn't work and when i use the import statement it throws error at point of deployment.

Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75

1 Answers1

6

in the same file define the first contract in an abstract form and within your current contract make the needed call,e.g:

 contract Coin1{
        function f() payable returns (uint);
    }


    contract Coin2{
        Coin1 coin;
        function setcoin(address addr) { coin= Coin1(addr); }
        function callcoin() { coin.f.value(10).gas(800)(); // you call the desired function here we call info with 800 gas; }
    }

you will find more detail on the official documentation about the External Function Calls

eth
  • 85,679
  • 53
  • 285
  • 406
Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75
  • Thank you for your response but when i do this i get the following error "member not found in argument dependent lookup" do i need to specify all the arguments in the live contract in the abstract form also? – coderwithattitude Jan 16 '17 at 12:46
  • and the constructor in coin gives me error "non empty returns directive" – coderwithattitude Jan 16 '17 at 12:49
  • @coderwithattitude Yes, you need to specify all arguments in the abstract form. Constructors don't return values so remove the returns in your constructor to fix it. – eth Jan 18 '17 at 05:58
  • thanks for your time, this is what worked for me incase anyone needs it. https://dappsforbeginners.wordpress.com/tutorials/interactions-between-contracts/ – coderwithattitude Jan 26 '17 at 07:02