2

When sending a TX, there's an optional gasPrice field. If I don't set it, what's it default to? Does it look at other TXs going on or is it a fixed value that only changes when web3 gets updated to a new version? Is there a way to get the default value so that I can, for example, add 1gwei to it? I'd like to ensure order of TXs in the same block by paying more for the first TX.

marked as duplicate by Ismael, shane, Richard Horrocks, Aquila, Achala Dissanayake Dec 29 '18 at 3:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

There is a web3.eth.gasPrice function. From the documentation (https://web3js.readthedocs.io/en/1.0/web3-eth.html#eth-gasprice):

The gas price is determined by the last few blocks median gas price.

So the gas price defaults to this value. You can of course change it but it doesn't make sense to try to order the txs with the gas price. Besides there is no way to ensure that txs you send end up in the same block.

  • Thanks! It wouldn't guarantee order but miners would prioritize the TX with higher gas price. Geth and Parity both do this: ethereum.stackexchange.com/questions/6107/… – Jonah Dec 28 '18 at 1:10
  • Instead of web3.eth.gasPrice I had to use web3.eth.getGasPrice() which is a promise that returns the median gas price. – Ahmed Akhtar Sep 1 at 19:43

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