Using Web3, we are able to estimate the amount of gas needed for a transaction

let estimatedGas = web3.eth.estimateGas({
    to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe",
    data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003"

contractObject.deploy().send({gas:estimatedGas, gasPrice: 2e9, ...})

Question: How can we estimate the gasPrice to use, instead of defining a static value like 2 Gwei?

3 Answers 3


Average gas price can be calculated (as a median for the last several blocks) by using the following code:

web3.eth.getGasPrice().then((result) => {
console.log(web3.utils.fromWei(result, 'ether'))
  • Do you know how they estimate 'slow....fast" gas prices? I'm looking to do something similar.
    – chovy
    Oct 14, 2021 at 7:38

You could use ETHGasStation.info by sending a GET request to this URL of their API:


This yields a response like this:

  "average": 46,
  "fastestWait": 0.5,
  "fastWait": 0.7,
  "fast": 131,
  "safeLowWait": 2.9,
  "blockNum": 6545673,
  "avgWait": 2.6,
  "block_time": 15.095744680851064,
  "speed": 0.5118320026004425,
  "fastest": 400,
  "safeLow": 40

The average field contains the GasPrice you should use for an average transaction wait time. safeLow contains the minimum price you should use at the moment. If you're in a rush, use fastest.


I think that we can just simply use web3.eth.gasPrice to get the suggest gas price.

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.