Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hardhat-gas-reporter

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hardhat-gas-reporter

Hardhat plugin for eth-gas-reporter, a mocha reporter for Ethereum test suites

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
110K
increased by11.7%
Maintainers
1
Weekly downloads
 
Created
Source

npm version Build Status Codechecks buidler

hardhat-gas-reporter

eth-gas-reporter plugin for hardhat.

What

A Mocha reporter for Ethereum test suites:

  • Gas usage per unit test.
  • Metrics for method calls and deployments.
  • National currency costs of deploying and using your contract system.
  • CI integration with codechecksbeta

Example report

Screen Shot 2019-06-23 at 2 10 19 PM

Installation

npm install hardhat-gas-reporter --save-dev

And add the following to your hardhat.config.js:

require("hardhat-gas-reporter");

Or, if you are using TypeScript, add this to your hardhat.config.ts:

import "hardhat-gas-reporter"

Looking for buidler-gas-reporter docs? They moved here...

Configuration

Configuration is optional.

module.exports = {
  gasReporter: {
    currency: 'CHF',
    gasPrice: 21
  }
}

:bulb: Pro Tip

The options include an enabled key that lets you toggle gas reporting on and off using shell environment variables. When enabled is false, mocha's (faster) default spec reporter is used. Example:

module.exports = {
  gasReporter: {
    enabled: (process.env.REPORT_GAS) ? true : false
  }
}

Usage

This plugin overrides the built-in test task. Gas reports are generated by default with:

npx hardhat test

Continuous Integration

This reporter comes with a codechecks CI integration that displays a pull request's gas consumption changes relative to its target branch in the Github UI. It's like coveralls for gas. The codechecks service is free for open source and maintained by MakerDao engineer @krzkaczor.

Complete set-up guide here (it's easy).

Screen Shot 2019-06-18 at 12 25 49 PM

Options

:warning: CoinMarketCap API change :warning:

Beginning March 2020, CoinMarketCap requires an API key to access currency market price data. The reporter uses an unprotected free tier key by default (10k reqs/mo). You can get your own API key here and set it with the coinmarketcap option.

OptionTypeDefaultDescription
enabledBooleantrueAlways generate gas reports when running the hardhat test command.
currencyString'EUR'National currency to represent gas costs in. Exchange rates loaded at runtime from the coinmarketcap api. Available currency codes can be found here.
coinmarketcapString(unprotected API key)API key to use when fetching current market price data. (Use this if you stop seeing price data)
gasPriceNumber(varies)Denominated in gwei. Default is loaded at runtime from the eth gas station api
outputFileStringstdoutFile path to write report output to
noColorsBooleanfalseSuppress report color. Useful if you are printing to file b/c terminal colorization corrupts the text.
onlyCalledMethodsBooleantrueOmit methods that are never called from report.
rstBooleanfalseOutput with a reStructured text code-block directive. Useful if you want to include report in RTD
rstTitleString""Title for reStructured text header (See Travis for example output)
showTimeSpentBooleanfalseShow the amount of time spent as well as the gas consumed
excludeContractsString[][]Contract names to exclude from report. Ex: ['Migrations']
srcString"contracts"Folder in root directory to begin search for .sol files. This can also be a path to a subfolder relative to the root, e.g. "planets/annares/contracts"
urlStringhttp://localhost:8545 (or network value)RPC client url
proxyResolverFunctionnoneCustom method to resolve identity of methods managed by a proxy contract.
showMethodSigBooleanfalseDisplay complete method signatures. Useful when you have overloaded methods you can't tell apart.
maxMethodDiffNumberundefinedCodechecks failure threshold, triggered when the % diff for any method is greater than number (integer)
maxDeploymentDiffNumberundefinedCodechecks failure threshold, triggered when the % diff for any deployment is greater than number (integer)
remoteContractsRemoteContract[][]Contracts pre-deployed to a (forked) network which the reporter should collect gas usage data for. (See RemoteContract type)

Documentation

Other useful documentation can be found at eth-gas-reporter

Keywords

FAQs

Package last updated on 02 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc