3.0.0-next.0 • Published 3 months ago

@solidstate/hardhat-contract-sizer v3.0.0-next.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Hardhat Contract Sizer

Output Solidity contract sizes with Hardhat.

Versions of this plugin prior to 3.0.0 were released as hardhat-contract-sizer, outside of the @solidstate namespace.

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

Installation

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

Usage

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:

optiondescriptiondefault
alphaSortwhether to sort results table alphabetically (default sort is by contract size)false
runOnCompilewhether to output contract sizes automatically after compilationfalse
flatwhether to hide the full path to the compilation artifact and output only the contract namefalse
strictwhether to throw an error if any contracts exceed the size limitfalse
onlyArray of String matchers used to select included contracts, defaults to all contracts if length is 0[]
exceptArray of String matchers used to exclude contracts[]
outputFilefile path to write contract size reportnull
unitunit of measurement for the size of contracts, which can be expressed in 'B' (bytes), 'kB' (kilobytes) or 'KiB' (kibibytes)KiB

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