Reputation: 5076
In ethers.js
you can use provider.getGasPrice()
to get a best-guess estimate of the gas you should pay. Is there anything simple I can call or transform onto this value in order to get what an equivalent of a "Fast" transaction would be instead of an "Average" speed transaction?
Upvotes: 3
Views: 14350
Reputation: 41
Maybe right now you have got the answer:
const gasPrice = await provider.getGasPrice()
const gasPrice = ((await provider.getFeeData()).gasPrice
Upvotes: 3
Reputation: 43581
The getGasPrice()
queries your provider JSON-RPC method eth_gasPrice and simply proxies whathever your provider returned.
In order to calculate the "Fast" and "Average" speed, you'll need to define what you consider these metrics. For example you can collect all transactions within the last 20 blocks (approx. 5 minutes) and look for percentiles in the historic data:
You can get transactions in a block using the getBlockWithTransactions() ethers.js method. In each transaction you're looking for the gasPrice
property.
Upvotes: 4