-
-
Notifications
You must be signed in to change notification settings - Fork 94
Fetch BNB, MATIC, AVAX, HR or MOVR gas price #251
Conversation
+1 |
1 similar comment
+1 |
This would be great 🚀 |
Hey @cgewecke could you please consider a review of this PR? |
@lucaperret Apologies, yes I will take a look over the weekend.... thanks for opening this. |
Hi @cgewecke, any chance you could look at it soon? This PR is opened since more than 3 months and seems that some people are looking forward to the merge and publishing. |
This is what I have been basically doing ... @lucaperret you were able to help me out on some great demos recently. "devDependencies": {
...
"eth-gas-reporter": "git+https://github.com/lucaperret/eth-gas-reporter#6ac872b599adcaa8aab40808576e769c6872eb38",
...
}, |
I would really ❤️ this feature, thanks! |
me too! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice, apologies for letting it languish.
I have a question about the use context and whether there needs to be some additional info in the README about accuracy of gas readings.
Many people will be running their tests against an ethereumjs-vm EVM using HardhatEVM or ganache.
I assume Polygon and BSC are consuming gas at similar rates to an ETH client because they are ETH forks, but is this the case for the other chains you've added support for here?
README.md
Outdated
| coinmarketcap | _String_ | (unprotected API key) | [API key][55] to use when fetching current market price data. (Use this if you stop seeing price data) | | ||
| gasPrice | _Number_ | (varies) | Denominated in `gwei`. Default is loaded at runtime from the `eth gas station` api | | ||
| token | _String_ | 'ETH' | The reference token for gas price | | ||
| gasPriceApi | _String_ | [ethgasstation](https://ethgasstation.info/json/ethgasAPI.json) | The API endpoint to retrieve the gas price. Could be also [BSC](https://api.bscscan.com/api?module=proxy&action=eth_gasPrice&apikey=YourApiKeyToken), [Polygon](https://api.polygonscan.com/api?module=proxy&action=eth_gasPrice&apikey=YourApiKeyToken), [Avalanche](https://api.snowtrace.io/api?module=proxy&action=eth_gasPrice&apikey=YourApiKeyToken), [Heco](https://api.hecoinfo.com/api?module=proxy&action=eth_gasPrice&apikey=YourApiKeyToken), [Moonriver](https://api-moonriver.moonscan.io/api?module=proxy&action=eth_gasPrice&apikey=YourApiKeyToken), | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default in this PR looks like it's no longer ethGasStation - it's an eth_gasPrice call to etherscan?
(Thanks for all these links! Great.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you consider adding a table below the config options with example tokens and gasPriceApi urls? If we can reliably fetch this data without an api key maybe that part of the url could be omitted?
Example token
and gasPriceApi
configurations
Any network call which returns a JSON-RPC response formatted as below is supported:
{"jsonrpc":"2.0","id":73,"result":"0x6fc23ac00"}
(By default, reporter calls https://api-cn.etherscan.com
for the Ethereum network gas price.)
Other networks include:
Network | token |
gasPriceApi |
---|---|---|
Binance | BNB | https://api.bscscan.com/api?module=proxy&action=eth_gasPrice |
Polygon | MATIC | https://api.polygonscan.com/api?module=proxy&action=eth_gasPrice |
Avalanche | AVAX | https://api.snowtrace.io/api?module=proxy&action=eth_gasPrice |
Heco | BIRD | https://api.hecoinfo.com/api?module=proxy&action=eth_gasPrice |
Moonriver | MOVR | https://api-moonriver.moonscan.io/api?module=proxy&action=eth_gasPrice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I made this change on the doc and config files.
mock/config-template.js
Outdated
@@ -12,6 +12,9 @@ module.exports = { | |||
reporterOptions: { | |||
currency: "chf", | |||
gasPrice: 21, | |||
token: "ETH", | |||
gasPriceApi: | |||
"https://api-cn.etherscan.com/api?module=proxy&action=eth_gasPrice&apikey=YourApiKeyToken", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I may butt in on this one, it would be appreciated to note in the README what the default gasPriceApi URL is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Have added a note above about possibly making a table of urls and token names for easy copy-pasting and that would be a good place to put any additional info about this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, also I changed the Etherscan endpoint to be compliant with their doc.
response = JSON.parse(response); | ||
config.gasPrice = Math.round(response.safeLow / 10); | ||
config.gasPrice = Math.round( | ||
parseInt(response.result, 16) / Math.pow(10, 9) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked this ... looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made some changes to take your comments into account. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Supports multiple tokens.