npm.io
2.10.1 • Published 1 year ago

hardhat-contract-sizer

Licence
MIT
Version
2.10.1
Deps
3
Size
24 kB
Vulns
0
Weekly
0
Stars
74

Hardhat Contract Sizer

Output Solidity contract sizes with Hardhat.

Versions of this plugin prior to 2.0.0 were released as buidler-contract-sizer.

Installation

npm install --save-dev hardhat-contract-sizer
# or
yarn add --dev hardhat-contract-sizer

Usage

Load plugin in Hardhat config:

require('hardhat-contract-sizer');

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
disambiguatePaths whether to output the full path to the compilation artifact (relative to the Hardhat root directory) false
strict whether to throw an error if any contracts exceed the size limit (may cause compatibility issues with solidity-coverage) 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 []
outputFile file path to write contract size report null
unit unit of measurement for the size of contracts, which can be expressed in 'B' (bytes), 'kB' (kilobytes) or 'KiB' (kibibytes) KiB
contractSizer: {
  alphaSort: true,
  disambiguatePaths: false,
  runOnCompile: true,
  strict: true,
  only: [':ERC20

Run the included Hardhat task to output compiled contract sizes:

npx hardhat size-contracts
# or
yarn run hardhat size-contracts

By 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
yarn run hardhat size-contracts --no-compile

Development

Install dependencies via Yarn:

yarn install

Setup Husky to format code on commit:

yarn prepare
], }

Run the included Hardhat task to output compiled contract sizes:

__CODE_BLOCK_3__

By default, the hardhat __INLINE_CODE_25__ task is run before sizing contracts. This behavior can be disabled with the __INLINE_CODE_26__ flag:

__CODE_BLOCK_4__

Development

Install dependencies via Yarn:

__CODE_BLOCK_5__

Setup Husky to format code on commit:

__CODE_BLOCK_6__

Keywords