11

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?

1 Answer 1

17

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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