May a message call change the gas price of the original transaction?

EOA's may call a contract function by means of a transaction. However, contracts can call each other in the execution environment.

Can message calls change the gas limit and gas price of the original transaction? If so, how would I do it in Solidity?


You can set a limit to the gas forwarded to the next contract but you can't change the gasPrice or overspend. That is to say, at the point where you forward gas to another contract, you're limited to the amount of unspent gas that exists at that stage of execution.

Here's a little syntax "by example": AbstractB(addressB).setX.value(1 ether).gas(10000)();

inspired by:

How to specify gas/value when making a call using abstract contracts?

Hope it helps.

  • Thank you - so, if a limit is set on the amount of gas the next contract can spend, does the current contract get to spend the unused gas? – Shuzheng Dec 20 '17 at 19:26
  • Unused gas is returned. By default, the callee receives all the available gas. Exception is send and transfer which now get only a stipend of 2300 as a protocol defence against rwentrance attacks. – Rob Hitchens Dec 20 '17 at 21:02
  • On case it's unclear, provided the limit was sufficient, the caller contract should end up with the same net available balance at the next step in any case. – Rob Hitchens Dec 20 '17 at 21:04
  • What if the called contract runs out of gas, and was called with, say, only half of the remaining gas of the calller. Does the caller has a chance to recover in this case? – Shuzheng Dec 22 '17 at 10:50
  • I believe the error will bubble up and revert the transaction - everything fails. – Rob Hitchens Dec 22 '17 at 15:17

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.