Is there any way in Solidity to change the gas price during contract method execution?
For example using Assembly?
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 communityCurrent
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:
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.