Web3.js: web3.eth.gasPrice is returning incorrect value

Created on 12 Dec 2017  路  6Comments  路  Source: ChainSafe/web3.js

As mentioned in documentation eth.gasPrice returns the current gas price. The gas price is determined by the x latest blocks median gas price.

But recently( 3 days ago), the ethereum network was congested and gas price increased to 60 GWei. But web3.eth.gasPrice was returning 21000000000 (21 Gwei).

I also checked some recent transactions on etherscan : 0xf5ccc6ecc36b318c8ac9794e2b472fa2f9b3acc0b2adf662b4f858b76a69c278, 0x123789fd42ad2037fff8bfaca3caeb6bec179b4630588902ae95c9515c742432, 0xf78960adb886d9a31549a04154ce459e00896dac6c7156e749c63f6755c5a4c9

All of them has the gas price of 60 Gwei. So why is eth.gasPrice is giving me 21GWei? I was relying on web3.eth.gasPrice function to get current safe gas price, but this doesn't seem to work normally.

Most helpful comment

+1

Happening to me as well. Right now, https://ethgasstation.info/ reports 8 while getGasPrice() returns 20.

image

All 6 comments

+1

+1

Happening to me as well. Right now, https://ethgasstation.info/ reports 8 while getGasPrice() returns 20.

image

@prashantprabhakar This is not a issue of web3.js because it gets the value from the node. The problem is that gas station does calculate it differently than geth.

@nivida This was not a comparison of eth gas station. I checked the txs on etherscan and last few blocks were using gas of 60Gwei but web3.eth.gasPrice was returning 21 wei.
However, eth gas station was also showing it to be 21 Gwei. I am not sure how web3 calculates its gas price but yes the estimates were incorrect and etherscan txs show a way high gas price than estimated by web3

did you try the below? I use the below but I suspect it also gives low gas price
Transfer transfer = new Transfer(web3, transactionManager);
BigInteger gasPrice = transfer.requestCurrentGasPrice();

here I use
import org.web3j.tx.FastRawTransactionManager; for transactionManager

@prashantprabhakar This happens because the gas price is determined by the x latest blocks median gas price from the current connected node. I would use the https://ethgasstation.info/ API if you really want to have an exact current gas price. The long term goal will be to improve the eth_gasPrice call on the node side or to implement the EthGasStation API for determining the current gas price of the connected network.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joeriexelmans picture joeriexelmans  路  3Comments

connectdotz picture connectdotz  路  3Comments

webersson picture webersson  路  3Comments

baxy picture baxy  路  3Comments

zamoore picture zamoore  路  3Comments