1

Is there any way in Solidity to change the gas price during contract method execution?

For example using Assembly?

1

Current

There is no way to change gas price during a transaction.

An example of the difficulty it might introduce is that a sender could promise a gas price of 20 gwei with 4M gas and reduce the gas price to 0 wei after 1M gas. The miner has now burned the time to run 1M worth of transaction gas, but can't collect it unless they finish the transaction. Their options are to:

  1. Abandon the current transaction, having wasted the first 1M gas worth of time
  2. Finish the transaction, giving the sender 3M worth of transaction cost for free

Future

There is a proposal to allow a transaction with arbitrary gas mechanisms, EIP 101, which is scheduled for Serenity. The proposed solution would allow for paying gas with other currencies, and "calling collect" for free transactions if the target contract supports it. In short, it says that the miner runs the potential transaction for up to 50k gas looking for a tx fee. From the EIP:

This process ensures that miners waste at most 50000 gas before knowing whether or not it will be worth their while to include the transaction, and is also highly general so users can experiment with new cryptography (eg. ed25519, Lamport), ring signatures, quasi-native multisig, etc. Theoretically, one can even create an account for which the valid signature type is a valid Merkle branch of a receipt, creating a quasi-native alarm clock.

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.