Introducing hardhat gas reporter.
In this tutorial, I hope to show you how to show you how to visualize the cost of a smart contract. This will help you along your journey on creating the most gas optimized contract!
Let's begin.
First lets create a hardhat contract directory by installing and initiating hardhat.
npm install --save-dev hardhat
Initialize hardhat
npx hardhat
Your screen should display this. You can create a basic sample project for starters.
Once in file directory, lets install hardhat gas reporter
npm install --save-dev hardhat-gas-reporter
Once installed, let's add all we need into our hardhat.config.js file .
In your hardhat.config.js file, add
require("hardhat-gas-reporter")
In module.exports add your gas reporter.
gasReporter: {
enabled: true,
outputFile: "gas-report.txt",
noColors: true,
currencey: "USD",
}
Of course you want to
npx hardhat compile
After that you are ready to run your test!! let's do it!
npx hardhat test
Should output a file similar to mine! All depends on what is is written in your test file!
Hope this helped!!! Feedback is greatly appreciated!