The contract contains ether. Can I buy the gas within the contract code?

  • You want to steal the gas ? find an exploit in the smart contract code! If there is no hack/exploit you can't. Otherwise if you're talking about the gas fees, only the miner who mines the block wins the gas.
    – Ellis
    Commented Jun 25, 2016 at 15:36
  • no, if i see, that msg.gas is small, i want bay gas for miner.
    – SkyN
    Commented Jun 25, 2016 at 18:02

1 Answer 1


Yes and no.

The gas has to be paid for, up front, by the original sender. There's no way to add more gas inside a transaction.

However, it's possible for a contract to reimburse the sender. It's also possible for the transaction to have a gasPrice of 0, and then the contract reimburses the miner via sending to msg.coinbase. In the latter case, a miner would have to be specifically programmed to accept that kind of transaction.

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