<
<
<
Hardhat 3 is now production ready. Migrate now
>
>
>

#Overview

@nomicfoundation/hardhat-network-helpers provides a convenient JavaScript interface to the JSON-RPC functionality of Hardhat Network.

Hardhat Network exposes its custom functionality primarily through its JSON-RPC API. However, for easy-to-read tests and short scripts, interfacing with the JSON-RPC API is too noisy, requiring a verbose syntax and extensive conversions of both input and output data.

This package provides convenience functions for quick and easy interaction with Hardhat Network. Facilities include the ability to mine blocks up to a certain timestamp or block number, the ability to manipulate attributes of accounts (balance, code, nonce, storage), the ability to impersonate specific accounts, and the ability to take and restore snapshots.

#Installation

TIP

This plugin is part of Viem Hardhat Toolbox and Ethers+Mocha Hardhat Toolbox. If you are using any of those toolboxes, there's nothing else you need to do.

To install this plugin, run the following command:

npm install --save-dev @nomicfoundation/hardhat-network-helpers

In your hardhat.config.ts file, import the plugin and add it to the plugins array:

import hardhatNetworkHelpers from "@nomicfoundation/hardhat-network-helpers";

export default {
  plugins: [hardhatNetworkHelpers],
};

#Usage

This plugin adds a networkHelpers property to each network connection:

import { network } from "hardhat";

const { networkHelpers } = await network.connect();

// immediately mine a new block
await networkHelpers.mine();

// mines a new block whose timestamp is 60 seconds after the latest block's timestamp.
await networkHelpers.time.increase(60);

For a full listing of all the helpers provided by this package, see the reference documentation.