hardhat-gas-reporter: Price data missing from report

I just finished integrating hardhat-gas-reporter into a new Advanced Sample Project that can be generated by the project initialization feature of the hardhat command-line interface. See https://github.com/nomiclabs/hardhat/pull/1632

However, I could not get the price data to show in the output. Re-posting from a comment on that PR:

  • Running with eth gas reporter doesn’t show anything in the USD column. Why does this happen? Maybe some missing config? Can we maybe remove it / use ETH?

I spent an hour trying to figure this out. I couldn’t get it to work.

I tried removing the currency from the config, and that made it default to EUR, but it still didn’t have any price data. I also tried changing the config to currency: "ETH", but that didn’t result in any meaningful data either. I also tried getting a CoinMarketCap API key and plugging it into the config, but that didn’t help either.

I even went in and debugged eth-gas-station, adding a console.log() statements to just before the call to coinmarketcap and just after. The one just before showed that the URL it was hitting was just fine (I pulled the url via curl and the data looks fine/legit to me (no error conditions or anything, and expected object fields seem fine)), but the console.log() statement just after the CMC call never gets executed, and I gave up on trying to figure out why.

For easy reference:

And here’s a paste of the output I’m seeing:

·----------------------------|----------------------------|-------------|-----------------------------·
|    Solc version: 0.8.4     ·  Optimizer enabled: false  ·  Runs: 200  ·  Block limit: 30000000 gas  │
·····························|····························|·············|······························
|  Methods                                                                                            │
·············|···············|··············|·············|·············|···············|··············
|  Contract  ·  Method       ·  Min         ·  Max        ·  Avg        ·  # calls      ·  usd (avg)  │
·············|···············|··············|·············|·············|···············|··············
|  Greeter   ·  setGreeting  ·           -  ·          -  ·      35426  ·            2  ·          -  │
·············|···············|··············|·············|·············|···············|··············
|  Deployments               ·                                          ·  % of limit   ·             │
·····························|··············|·············|·············|···············|··············
|  Greeter                   ·           -  ·          -  ·     497002  ·        1.7 %  ·          -  │
·----------------------------|--------------|-------------|-------------|---------------|-------------·

Reproducing would be easy if you checked out and built the hardhat monorepo and then in an empty folder did yarn init --yes && yarn add --file:/path/to/monorepo/packages/hardhat-core && yarn hardhat and selected “advanced project” and then did REPORT_GAS=true yarn hardhat test. And it would be even easier than that if you were to wait until this functionality is officially released.

Please let me know if this is my error or if I’m having the wrong expectations.

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 27 (10 by maintainers)

Most upvoted comments

@kazazor I think you’ll need to get your own free-tier coinmarketcap api key, here and set the option in your config:

gasReporter: {
    currency: "USD",
    coinmarketcap: "abcde-....",
    gasPrice: 90,
  },

The limit on the shared key is not per plugin user but rather for all users of the plugin. It’s rate limited almost instantly now that the package is widely used … you have to have your own credentials for price reporting to work unfortunately.

Just lmk if doing that doesn’t work and I will re-open this issue and investigate.

@feuGeneA

I think you could get price data by introducing a small delay in your “internal” hh test here.

But ultimately the problem is a race-condition in eth-gas-reporter and the sync-ness of mocha’s third-party reporter api. This race-condition shouldn’t affect most people though - their test suites typically run longer than the latency of the CMC request.

To fix I will need to fetch the price in TASK_TEST_RUN_MOCHA_TESTS here (where async is supported) and create a configuration option at eth-gas-reporter for this data.

Sorry about this…I’m sure it was annoying to debug 😅