4

I'm using web3.js to get the minimum gas price, but the following is not working:

web3.eth.getBlock('latest').minimumGasPrice

How can I do this?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Owans
  • 1,037
  • 5
  • 14

1 Answers1

9

You can do this using web3.js like so:

const block = await web3.eth.getBlock('latest');
const minimumGasPrice = block.minimumGasPrice;

Note that getBlock() involves a network request, and therefore needs an await.

Your question only asked for a way to do this in Javascript, but if you want to do the equivalent using terminal commands, in case you have not done so yet, check out the answer on this similar question: How to calculate what gas price to use for transactions on RSK?

Note: If you're coming from Ethereum development, the minimumGasPrice field in this RPC response is RSK-only - do not expect the same from Ethereum.

bguiz
  • 27,371
  • 47
  • 154
  • 243
7alip
  • 895
  • 6
  • 11