Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
hardhat-gas-trackooor
Advanced tools
Readme
Hardhat plugin to track gas on the transaction level.
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"
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:
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:
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);
});
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 |
FAQs
Hardhat plugin to track gas on the transaction level
The npm package hardhat-gas-trackooor receives a total of 5 weekly downloads. As such, hardhat-gas-trackooor popularity was classified as not popular.
We found that hardhat-gas-trackooor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.