写些程序来测试我们的操作将消耗多少gas费用。
yarn add -D hardhat-gas-reporter
import "hardhat-gas-reporter"
const config: Config = {
...,
networks: {
hardhat: {
chainId: 31337
},
...
},
gasReporter: {
enabled: true
}
};
pragma solidity ^0.8.24
contract TestGas {
uint a;
uint b;
uint c;
function test1() public {
a++;
}
function test2() public {
a++;
b++;
}
function test3() public {
a++;
b++;
c++;
}
function test4() public {
c = a + b;
}
function test5() public {
test4();
b = a + c;
}
}