Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web3.eth.gasPrice is returning incorrect value #1230

Closed
prashantprabhakar opened this issue Dec 12, 2017 · 6 comments
Closed

web3.eth.gasPrice is returning incorrect value #1230

prashantprabhakar opened this issue Dec 12, 2017 · 6 comments
Assignees

Comments

@prashantprabhakar
Copy link

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.

@kn1g
Copy link

kn1g commented Jan 13, 2018

+1

@woniesong92
Copy link

+1

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

image

@nivida nivida self-assigned this Aug 9, 2018
@nivida nivida added Bug Addressing a bug and removed Bug Addressing a bug labels Aug 9, 2018
@nivida
Copy link
Contributor

nivida commented Aug 16, 2018

@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 nivida closed this as completed Aug 16, 2018
@prashantprabhakar
Copy link
Author

@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

@hd51515
Copy link

hd51515 commented Feb 14, 2019

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

@nivida
Copy link
Contributor

nivida commented Feb 18, 2019

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants