Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

hardhat-gas-trackooor

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Issues
File Explorer

Advanced tools

hardhat-gas-trackooor

Hardhat plugin to track gas on the transaction level

    1.0.2latest

Version published
Maintainers
1
Yearly downloads
821

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

Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc