0

Let's say I've got a contract called MyContract. My contract has a function which receives calldata and an address for another contract, called OtherContract

I want to be able to take the calldata and address in MyContract, and execute the callData in OtherContract from MyContract.

I don't know anything about the OtherContract, or the function that uses the calldata.

Is this possible?

Thanks for your time!!!

1 Answer 1

3

Yes, it is possible to call an arbitrary function with only address and data.

function foo(address target, bytes memory data) external { // Make the function call (bool success, bytes memory result) = target.call(data); // success is false if the call reverts, true otherwise require(success, "Call failed"); // result contains whatever has returned the function emit ExecutionResult(success, result); } 

You can check if the function call revert or not. Since you don't know anything else about the contract it is not possible to interpret the result but you can return them.

Making a call changes msg.sender. To the target contract it will seem the contract making the call is the sender.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.