Socket
Socket
Sign inDemoInstall

hardhat-gas-trackooor

Package Overview
Dependencies
294
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

hardhat-gas-trackooor

Hardhat plugin to track gas on the transaction level


Version published
Maintainers
1
Weekly downloads
11
increased by57.14%
Bundle size
1.1 kB
Minified + gzipped

Weekly downloads

Readme

Source

hardhat-gas-trackooor

Hardhat plugin to track gas on the transaction level.

Example report

Example

Installation

npm install hardhat-gas-trackooor --save-dev

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

require("hardhat-gas-trackooor");

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

import "hardhat-gas-trackooor"

Usage

Inside your tests, wrap your contract with the GasTracker class:

it("Should return the new greeting once it's changed", async function () {
    const Greeter = await ethers.getContractFactory("Greeter");
    const greeter = new GasTracker(await Greeter.deploy("Hello, world!"), {
      logAfterTx: true,
    })
    await greeter.setGreeting("Hola, mundo!");
    expect(await greeter.greet()).to.equal("Hola, mundo!");
  });

Then run

npx hardhat test

Example Output: output

Or, if you would like to specify which functions you want to get the gas for, you can use GetGas(transaction):

  it("Should return the new greeting once it's changed", async function () {
    const Greeter = await ethers.getContractFactory("Greeter");
    const greeter = await Greeter.deploy("Hello, world!");
    const gas = await GetGas(await greeter.setGreeting("Hola, mundo!"));
    console.log('Gas used: '+gas);
    expect(await greeter.greet()).to.equal("Hola, mundo!");
  });

NOTE: GetGas() does not work with a GasTracker wrapped contract at the moment.

Output: output

If you do not want to log gas to the console but still want to take advantage of the gas logging, gas data from transactions are logged to [wrappedContract].GasData:

it("Should return the new greeting once it's changed", async function () {
    const Greeter = await ethers.getContractFactory("Greeter");
    const greeter = new GasTracker(await Greeter.deploy("Hello, world!"), {
      logAfterTx: false, // set to false so it doesn't log
    })
    await greeter.setGreeting("Hola, mundo!");
    expect(await greeter.greet()).to.equal("Hola, mundo!");

    // access gas data through greeter.GasData;
    const gasData = greeter.gasData;
    console.log(gasData);
});

Options

There are not many options yet, feel free to make an issue or pull request if you want to add any.

OptionTypeDefaultDescription
logAfterTxBooleanfalseLog gas after each transaction

Keywords

FAQs

Last updated on 19 Feb 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc