If I call a function of Contract1, that creates/calls another Contract2. Who pays the gas used to call Contract2 ?

I think it's Contract1 - the second msg.sender. In that case, how can I make the original msg.senderpay?

up vote 13 down vote accepted

Gas and value in a transaction are entirely separate. When you send x ETH to an address, whether from an account or a contract, the recipient's balance is guaranteed to go up by x, regardless of how much gas was used (as long as there are no exceptions).

Additionally, gas is always paid by the original sender (tx.origin in Solidity), not by any intermediate contracts. The gas used in a transaction is always subtracted from the balance of the sendimg account, not of a contract.

tl;dr: you don't need to do anything, just send enough gas in the transaction

  • To highlight an exception for "recipient's balance is guaranteed to go up", is if the recipient is a contract that rejects Ether – eth Feb 19 '16 at 13:30
  • I thought that was covered in the "(as long as there are no exceptions)", but I guess I should be clearer – Tjaden Hess Feb 19 '16 at 14:29
  • Yes you covered it, just wanted to highlight the fallback case – eth Feb 19 '16 at 14:37

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.