0
votes

I have a problem which I'm trying to figure out for a week I think I'm 90% there.

If I deploy a contract MerchantA on a private blockchain and retrieve it's contract address and ABI through the solidity command line solc --abi MerchantA.sol and store it.

Where do I enter this ABI & Address in a brand new contract say inside SendMoneyContract method where calls one of the function of AnimalContract deployed at address 0xrandom.

The material I'm finding online has been to include both solidity source code in the same file but for my case, I can't do it. Reason being MerchantAContract is unique for each deployment [each merchant added gets a unique contract`.

So far, from my understanding, I need to include the MerchantA contract address and ABI. I have no idea how to do it inside the solidity function.

1

1 Answers

2
votes

You do not do anything with the ABI. Let's say you want to call the functionA function on MerchantA FROM MerchantB, all you do is take the interface from MerchantA, an example of an interface of an ERC20 token is:

contract Token {
  function totalSupply() constant returns (uint256 supply) {}
  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;
}

On MerchantB, wherever you want to call functionA, you put the following code:

MerchantA merchantA = MerchantA(0x0000000000000000000000000000000000000000); //Replace 0x000000000000000000000000000000000000000 with the address of MerchantA
merchantA.functionA();

You will need to swap out the interface of MerchantA because you are not using an ERC20 token as well as what function you want to call.