2

As far as I understand if a caller uses just one function from a callee contract it only needs to know the signature of this function, not the whole interface.

Callee.sol (Kovan):

contract Callee{

    uint public anyNumber;

    function theOnlyFunctionCallerNeeds (uint someData) external {
        anyNumber = someData;
    }

    function justSomeRandomFunction(uint someOtherData) public view returns (uint){
        return anyNumber + someOtherData + 42;
    }
}

Caller.sol (Kovan):

interface Callee{
    function theOnlyFunctionCallerNeeds (uint);
}

contract Caller{

    Callee callee;
    uint public anyNumber;

    function Caller(address calleeAddr) public {
        callee = Callee(calleeAddr);
    }

    function usingCallee(uint callerData) external {
        callee.theOnlyFunctionCallerNeeds(callerData);
    }
}

It works on testnet (Kovan) but I cannot find it anywhere in the docs. So my question is can I use this pattern to write upgradable contracts (so I could easily change Callee contract except for one function)? Is there anything to be considered?

3

No, the Caller doesn't need to know the complete interface of the Callee. As you have stated :

As far as I understand if a caller uses just one function from a callee contract it only needs to know the signature of this function, not the whole interface.

The calling contract isn't omniscient, it cannot know if the interface you gave is complete or not. So, by giving the functions you want in the interface, you are just telling it that it can use these functions to interact with the Callee and "how to behave" when doing so.

0

What is the reason for writing this code in Caller.sol?

interface Callee{
function theOnlyFunctionCallerNeeds (uint);}
  1. you can use any public function of Callee without that code;
  2. you use interface keyword if you want to create contract with functions without body Inherit from it and implement bodies. But you do not inherit.

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.