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.
1 Answer
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/…– JonahDec 28, 2018 at 1:10
-
2Instead of
web3.eth.gasPrice
I had to useweb3.eth.getGasPrice()
which is a promise that returns the median gas price. Sep 1, 2019 at 19:43