@solidstate/hardhat-contract-sizer
v3.0.0
Published
Output Solidity contract sizes with Hardhat
Maintainers
Readme
Hardhat Contract Sizer
Output Solidity contract sizes with Hardhat.
Versions of this plugin prior to
3.0.0were released ashardhat-contract-sizer, outside of the@solidstatenamespace.
Versions of this plugin prior to
2.0.0were released asbuidler-contract-sizer.
Installation
npm install --save-dev @solidstate/hardhat-contract-sizer
# or
pnpm add -D @solidstate/hardhat-contract-sizerUsage
Load plugin in Hardhat config:
import HardhatContractSizer from '@solidstate/hardhat-contract-sizer';
const config: HardhatUserConfig = {
plugins: [
HardhatContractSizer,
],
contractSizer: {
... // see table for configuration options
},
};Add configuration under the contractSizer key:
| option | description | default |
| -------------- | --------------------------------------------------------------------------------------------------------------------------- | ------- |
| alphaSort | whether to sort results table alphabetically (default sort is by contract size) | false |
| runOnCompile | whether to output contract sizes automatically after compilation | false |
| flat | whether to hide the full path to the compilation artifact and output only the contract name | false |
| strict | whether to throw an error if any contracts exceed the size limit | false |
| only | Array of String matchers used to select included contracts, defaults to all contracts if length is 0 | [] |
| except | Array of String matchers used to exclude contracts | [] |
| unit | unit of measurement for the size of contracts, which can be expressed in 'B' (bytes), 'kB' (kilobytes) or 'KiB' (kibibytes) | KiB |
Additional configuration options are provided by @solidstate/hardhat-git, which is included as a dependency.
Run the included Hardhat task to output compiled contract sizes:
npx hardhat size-contracts
# or
pnpm hardhat size-contractsBy default, the hardhat compile task is run before sizing contracts. This behavior can be disabled with the --no-compile flag:
npx hardhat size-contracts --no-compile
# or
pnpm hardhat size-contracts --no-compileDevelopment
Install dependencies via pnpm:
pnpm installSetup Husky to format code on commit:
pnpm prepare