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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With