npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hardhat-gas-trackooor

v1.0.4

Published

Hardhat plugin to track gas on the transaction level

Downloads

35

Readme

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.

| Option | Type | Default | Description | | ----------------- | ---------------------- | -------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | logAfterTx | Boolean | false | Log gas after each transaction