I am little bit lost related to gas refund issue. On the following answer: https://ethereum.stackexchange.com/a/11017/4575 it has been mentioned that:

However, if things do get crowded and miners do not include your transaction right away you can increase the gas price. This is analogous to a "higher priority" in other systems: https://stackoverflow.com/questions/33802037/in-ethereum-what-is-gas-how-is-it-used-and-what-is-the-difference-between-st.

Therefore to get a higher priority for a transaction to be mined, would it be a good idea to send a transaction with highest gasPrice (for example: myContract.hello(var, {from: web3.eth.accounts[0], gas: 99570000 , gasPrice: 50000000000 }); ), since as I understand unused gas will be automatically and immediately refunded. if the gasUsed for the hello() function is 1000000, will I get refund for 50000000000 - 1000000 ? or all the gas I send via transaction will be spent?

Please note that I updated my question based on @Badr Bellaj's guidance.

1 Answer 1


Don't confuse gas value with gasprice.

web3.eth.sendTransaction({/* ... */,gas: 99570000 , gasPrice: 12345});

Miners will Prioritize the transactions with a higher gas price not a gas value (how much gas are you providing to be used to execute your transaction). the miners set a gasprice(the gas price you are willing to pay in ether for each unit of gas) whiting the network if you send a transaction with a price below your transaction will not be proceeded otherwise more you raise your gas price more you Prioritize your transaction. your transaction fee = consumed_gas * gas_price. your function consumes n gas you get refunded gas_value-n;

  • Thank you for your answer. ex: web3.eth.sendTransaction({/* ... */, gas: 99570000 , gasPrice: 50000000000}); in either cases when I give a very high value for a transaction that is using a low gas (for example: 1000000), will there be any refund? I am going to call the same transaction inside a infinite loop, so I was not sure that using a large gasPrice may lead me to have insufficient gas much quickly or not.
    – alper
    Dec 30, 2016 at 15:17
  • 1
    your transaction execution consumes gas and you pay using gasprice. the billing will be consumed_gas*gas_price. so every time the calculation reduces the gas value. e.g you send a transaction with 1234 gas and the function consumes 4 gas you get refunded 1230 gas (unite). Think of a gas like a vocher in a casino, you play with but the casino who sets its value so you play with units=vocher not money.
    – Badr Bellaj
    Dec 30, 2016 at 15:57
  • "Infinite Loop"? The EVM is designed with the goal of making sure an infinite loop isn't possible. Dec 30, 2016 at 18:34
  • Ups sorry for the confusion, I implemented a infinite loop on my bash script so every 20 seconds it will call the same transaction. @RobHitchens
    – alper
    Dec 30, 2016 at 19:14
  • 1
    No. The remaining gas units are refunded
    – Badr Bellaj
    Dec 30, 2016 at 20:31

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.