Giter VIP home page Giter VIP logo

hardhat-gas-reporter's Introduction

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
  }
}

๐Ÿ’ก Pro Tips

Turning the plugin on/off

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
  }
}

Migrating from Truffle

If you already have eth-gas-reporter installed in your project, make sure you uninstall it before adding this plugin. hardhat-gas-reporter manages eth-gas-reporter as a dependency and having multiple versions in your lockfile can stop the reporter from working correctly.

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

โš ๏ธ CoinMarketCap API change โš ๏ธ

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.

Option Type Default Description
enabled Boolean true Always generate gas reports when running the hardhat test command.
currency String 'EUR' National currency to represent gas costs in. Exchange rates loaded at runtime from the coinmarketcap api. Available currency codes can be found here.
coinmarketcap String (unprotected API key) API key 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
outputFile String stdout File path to write report output to
noColors Boolean false Suppress report color. Useful if you are printing to file b/c terminal colorization corrupts the text.
onlyCalledMethods Boolean true Omit methods that are never called from report.
rst Boolean false Output with a reStructured text code-block directive. Useful if you want to include report in RTD
rstTitle String "" Title for reStructured text header (See Travis for example output)
showTimeSpent Boolean false Show the amount of time spent as well as the gas consumed
excludeContracts String[] [] Contracts (or folders) to exclude from report. Ex: ['Migrations.sol', 'Wallets/']. (See v1.0.3 release notes for additional usage help)
src String "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"
url String http://localhost:8545 (or network value) RPC client url
proxyResolver Function none Custom method to resolve identity of methods managed by a proxy contract.
showMethodSig Boolean false Display complete method signatures. Useful when you have overloaded methods you can't tell apart.
maxMethodDiff Number undefined Codechecks failure threshold, triggered when the % diff for any method is greater than number (integer)
maxDeploymentDiff Number undefined Codechecks failure threshold, triggered when the % diff for any deployment is greater than number (integer)
remoteContracts RemoteContract[] [] Contracts pre-deployed to a (forked) network which the reporter should collect gas usage data for. (See RemoteContract type and usage example)

Documentation

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

hardhat-gas-reporter's People

Contributors

cgewecke avatar alcuadrado avatar dependabot[bot] avatar frangio avatar fvictorio avatar pedrocrvz avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.