Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the minimum gas price on RSK with web3.js?

Tags:

rpc

web3js

rsk

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?

like image 283
Owans Avatar asked Mar 01 '23 15:03

Owans


1 Answers

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.

like image 53
7alip Avatar answered Mar 19 '23 21:03

7alip