Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Fetch BNB, MATIC, AVAX, HR or MOVR gas price #251

Merged
merged 4 commits into from
Nov 25, 2021

Conversation

lucaperret
Copy link
Contributor

Supports multiple tokens.

@cblanquera
Copy link

+1

1 similar comment
@ASlowCheetah
Copy link

+1

@enzoferey
Copy link

This would be great 🚀

@lucaperret
Copy link
Contributor Author

Hey @cgewecke could you please consider a review of this PR?

@cgewecke
Copy link
Owner

@lucaperret Apologies, yes I will take a look over the weekend.... thanks for opening this.

@lucaperret lucaperret changed the title feat(gas): allow to fetch BNB and MATIC price Fetch BNB, MATIC, AVAX, HR or MOVR gas price Nov 4, 2021
@lucaperret
Copy link
Contributor Author

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.
Thank you in advance,
Luca

@cblanquera
Copy link

cblanquera commented Nov 12, 2021

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",
  ...
},

@shannonwells
Copy link

I would really ❤️ this feature, thanks!

@irux
Copy link

irux commented Nov 21, 2021

me too!

Copy link
Owner

@cgewecke cgewecke left a 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), |
Copy link
Owner

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.)

Copy link
Owner

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

Copy link
Contributor Author

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.

@@ -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",
Copy link

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.

Copy link
Owner

@cgewecke cgewecke Nov 25, 2021

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.

Copy link
Contributor Author

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked this ... looks good.

Copy link
Contributor Author

@lucaperret lucaperret left a 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.

@cgewecke cgewecke self-requested a review November 25, 2021 18:23
Copy link
Owner

@cgewecke cgewecke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants