[TWIL] Week of May 19, 2024
![[TWIL] Week of May 19, 2024](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1717055547035%2F44fc37ed-bdc2-4279-9c0e-d28c1c68f298.png&w=3840&q=75)
This week, while working on creating smart contracts, I discovered a couple of great tools from a tutorial in Base's official documentation. I'll share what I learned:
Hardhat Gas Reporter Plugin
This plugin is essential if you're developing with Hardhat, Truffle, or any other smart contract development tool that supports it. When you run tests, it automatically creates a table of stats, showing the average gas used for each method in your smart contracts. The installation is quick and easy:
Run
npm install -D hardhat-gas-reporterAdd the following to
hardhat.config.ts:import "hardhat-gas-reporter"; // other imports... const config: HardhatUserConfig = { // other configs... gasReporter: { enabled: true, }, };Once you write your smart contract and test code, run
npx hardhat test, and you'll see a table of stats.
With the resulting report, you can see how much gas is used for each transaction. This helps you estimate the cost of each transaction and decide if you need to optimize the smart contract code for better gas efficiency.
Solidity Optimizer
This helps optimize your Solidity code for gas efficiency. To use it, add the following to hardhat.config.ts:
const config: HardhatUserConfig = {
solidity: {
// ...
settings: {
optimizer: {
enabled: true,
runs: <number>,
},
},
},
};
Here, <number> depends on your preference. If <number> is high, the optimizer focuses on making the Solidity code more gas-efficient for each method execution, but it costs more to deploy the smart contract. If <number> is low, the deployment cost of the smart contract will be lower, but each method will cost more to execute.




![[TWIL] Week of August 11, 2024](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1724192926501%2F2ba38d69-5f89-4c41-b2fe-7f994fa97f71.png&w=3840&q=75)
![[TWIL] Week of August 04, 2024](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1723410046529%2F77c9c1f6-e0e2-4422-aa2c-0b82b769631c.png&w=3840&q=75)
![[TWIL] Week of July 28, 2024](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1723335244607%2F22b5f8ee-4c35-4cf0-9666-405c09aae03c.png&w=3840&q=75)