1

I have my Callee contract in Callee.sol

pragma solidity ^0.5.1;

contract Callee {
  uint private val;

  constructor() public{
    val = 30;
  }
  function getValue() public view returns(uint) {
      return val;
  }
  function increment() public returns(uint) {
    val = val + 1;
    return val;
  }
}

and I have another contract Caller.sol where i have to use Callee functions. should i use inheritance

pragma solidity ^0.5.1;
import "./Callee.sol";

contract Caller is Callee{

    // Callee public c;
    // constructor(address addr) public {
    //  c = Callee(addr);
    // }
    function someAction() public returns(uint){
      return getValue();
    }
    function inc() public returns(uint){
      return increment();
    }

}

OR should i use contract creation method by new?

pragma solidity ^0.5.1;
import "./Callee.sol";

contract Caller{

    Callee public c;
    constructor() public {
      c = new Callee();
    }
    function someAction() public view returns(uint){
      return c.getValue();
    }
    function inc() public returns(uint){
      return c.increment();
    }
}

also if I am building my ICO dapp where I have two contracts ERC20Token.sol and MYICO.sol where MYICO will be used to buy token etc. then which one of the above methods shoild i use to ERC20Token.sol from MYICO.sol?

0

How about deploying your Callee independently and sending that address as constructor parameter when you deploy the Caller?

contract Caller {
    Callee callee;

    constructor(address _callee) {
        callee = Callee(_callee);
    }
}

Does your Caller have properties (show behavior) of Callee then yes, you can go with inheritance. But, for the ICO your second and the one I gave are the generally used solutions.

ERC20Token is the Callee and MYICO is the Caller.

  • so, if person A calls to Caller(here msg.sender will be address of A) which in turn calls to Callee, then in Callee msg.sender will be the address of Caller not A. Right? – Prakash Ujjwal Jun 22 at 20:28
  • Yes, correct. The msg.sender in the Callee will be the Caller and not the A. – biplavo Jun 23 at 4:24
  • If this answered your query try to upvote it and select this as answer. – biplavo Jun 24 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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