eth-gas-reporter: Gas Usage for Ethereum Tests

0.2.27 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

/* truffle-config.js */
const HDWalletProvider = require('@truffle/hdwallet-provider'); // Example dependency for network config

module.exports = {
  networks: {
    development: {
      host: '127.0.0.1',
      port: 8545,
      network_id: '*',
    },
    goerli: {
      provider: () => new HDWalletProvider(
        process.env.MNEMONIC ?? 'your_mnemonic_here',
        `https://goerli.infura.io/v3/${process.env.INFURA_PROJECT_ID ?? ''}`
      ),
      network_id: 5,
      gasPrice: 10000000000, // 10 Gwei
      confirmations: 2,
      timeoutBlocks: 200,
      skipDryRun: true
    },
  },
  mocha: {
    reporter: 'eth-gas-reporter',
    reporterOptions : {
      currency: 'USD',
      token: 'ETH',
      gasPrice: 20, // Example fixed gas price in Gwei
      coinmarketcap: process.env.COINMARKETCAP_API_KEY ?? '', // Required for currency conversions
      outputFile: 'gas-report.txt',
      noColors: false,
      rst: true, // Use ReStructuredText format for output
      rstTitle: 'Gas Usage Report'
    }
  },
  compilers: {
    solc: {
      version: '0.8.0', // Specify your Solidity compiler version
    },
  },
};

view raw JSON →