normally I call external contracts by importing an interface of the external contract and generating a "local variable" of the contract, once I need it. Something like this:
import "./CalleeInterface";
contract Caller {
function callExternalFunction(address _calleeAddr){
CalleeInternface callee = CalleeInterface(_calleeAddr);
callee.someExternalFunction();
}
My problem is, that above way seems to use function call
implicitly.
Now I am facing a situation, where the external function checks the address of the sender. When I use above way, msg.sender
is the address of contract Caller
. Since I want to "forward" the address of the actual caller, I need to call the external function using delegatecall
:
contract Caller {
function callExternalFunction(address _calleeAddr){
_calleeAddr.delegatecall(bytes4(keccak256("someExternalFunction()")));
}
As you can see, the interface is not required in this situation, but the code is a bit more complex.
Now my question is, if there is a way to use delegatecall
with the "interface way" of calling external function?