# hardhat-contract-sizer

> Output Solidity contract sizes with Hardhat

Latest version **2.10.1** (published 2025-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install hardhat-contract-sizer
pnpm add hardhat-contract-sizer
yarn add hardhat-contract-sizer
bun add hardhat-contract-sizer
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.10.1 |
| Published | 2025-08-09 |
| First published | 2020-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 24.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 74 |
| Author | Nick Barry |
| Maintainers | itsnickbarry |
| Keywords | hardhat, buidler, abi, solidity, solc, smart-contracts, ethereum, blockchain, wow, bytecode |

## Links

- npm: https://www.npmjs.com/package/hardhat-contract-sizer
- Repository: https://github.com/ItsNickBarry/hardhat-contract-sizer
- npm.io page: https://npm.io/package/hardhat-contract-sizer

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [cli-table3](https://npm.io/package/cli-table3.md) ^0.6.0
- [strip-ansi](https://npm.io/package/strip-ansi.md) ^6.0.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.10.1 (latest) — 2025-08-09
- 2.10.0 — 2023-06-13
- 2.9.0 — 2023-05-22
- 2.8.0 — 2023-02-06
- 2.7.0 — 2023-01-12
- 2.6.1 — 2022-06-30
- 2.5.1 — 2022-03-21
- 2.5.0 — 2022-02-24
- 2.4.0 — 2022-01-17
- 2.3.1 — 2022-01-10
- 2.3.0 — 2021-12-22
- 2.2.0 — 2021-12-20
- 2.1.1 — 2021-09-18
- 2.1.0 — 2021-09-13
- 2.0.3 — 2021-03-04
- … 3 more at https://npm.io/package/hardhat-contract-sizer/versions

## README

# 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

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

## Usage

Load plugin in Hardhat config:

```javascript
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`   |

```javascript
contractSizer: {
  alphaSort: true,
  disambiguatePaths: false,
  runOnCompile: true,
  strict: true,
  only: [':ERC20$'],
}
```

Run the included Hardhat task to output compiled contract sizes:

```bash
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:

```bash
npx hardhat size-contracts --no-compile
# or
yarn run hardhat size-contracts --no-compile
```

## Development

Install dependencies via Yarn:

```bash
yarn install
```

Setup Husky to format code on commit:

```bash
yarn prepare
```

---
_Source: https://npm.io/package/hardhat-contract-sizer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
