eth-gas-reporter is a Mocha reporter designed to provide detailed gas usage metrics for Ethereum smart contract unit tests. It helps developers optimize contract efficiency by displaying gas consumption per test, method calls, and deployments. The current stable version is 0.2.27 as of April 2026. While an explicit release cadence isn't stated, the changelog shows consistent updates over time, indicating active maintenance. Key differentiators include its integration with popular Ethereum development environments like Truffle and Hardhat (via a plugin), the ability to calculate real-world national currency costs, and CI integration via Codechecks for tracking gas changes across pull requests. It supports various tokens for price calculation like ETH, BNB, MATIC, AVAX, HT, or MOVR.
npm install eth-gas-reporterVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to configure `eth-gas-reporter` within a `truffle-config.js` file, including example network setup and various reporter options for currency, token, and output format.
Obtain a free API key from CoinMarketCap and set it via the `coinmarketcap` option in `reporterOptions` or as an environment variable (e.g., `process.env.COINMARKETCAP_API_KEY`).
Ensure your project's Mocha version is compatible with v10. Refer to Mocha's official migration guide for potential breaking changes and necessary adjustments.
Install `hardhat-gas-reporter` (`npm install --save-dev hardhat-gas-reporter`) and configure it in your `hardhat.config.js` using `require('hardhat-gas-reporter');` or `import 'hardhat-gas-reporter';`.No direct user action is required for typical usage. If you were extending or deeply integrating with internal `ethers` utilities, review your code for compatibility with `ethers` v5 or newer's `utils` module.
Launch your Ethereum client (e.g., Ganache, Hardhat Network) as a separate process and connect to it over RPC. Avoid in-process providers for test execution with this reporter.
Obtain a valid API key from CoinMarketCap and set it using the `coinmarketcap` option in your `reporterOptions` configuration or as an environment variable.
Ensure `eth-gas-reporter` is installed as a dev dependency (`npm install --save-dev eth-gas-reporter`) and that your Mocha configuration correctly specifies its name: `reporter: 'eth-gas-reporter'`.
Install the specific plugin for Hardhat/Buidler: `npm install --save-dev hardhat-gas-reporter` and include it in your configuration file using `require('hardhat-gas-reporter');`.