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.sender
pay?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityIf 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.sender
pay?
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