0

Looking at this article about contract interactions, I saw this line of code:

someAddress.call.gas(1000000).value(1 ether)("register", "MyName");

With the explanation:

It’s also possible to provide gas and ether for a call invocation

I went on to modify the call. in the provided Caller.sol contract like this:

addr.call.gas(1000000).value(1 ether)(bytes4(keccak256("storeValue(uint256)")), 100);

To understand how providing gas would work. The remix output was not particularly insightful, so here I am hoping to get answers. Does the caller account provide gas units for Caller.sol to use while calling the Callee.sol function? If yes, how does this work? How are said gas units aquired? What happens to leftover gas? Or does it mean I am providing enough fees to cover this amount of gas expended? Thanks for any clarifications on the matter.

0

Gas is deducted from the transaction unspent gas, so it is gas already paid by the transaction's sender.

Using v0.8 syntax it looks cleaner

addr.call{gas: 1000000, value: 1 ether}(...

If before the call there were 50,000 unspent gas then the call can use at most 50,000 gas. (Actually it will receive a little less because as part of EIP 150 a fraction is used as reserve).

Unspent gas by the callee are returned to the caller.

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.