>
>
Complete the 2023 Solidity Survey here
>
>

#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. See the extensive set of methods available in its reference documentation. 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

npm 7+
npm 6
yarn
npm install --save-dev @nomicfoundation/hardhat-network-helpers
npm install --save-dev @nomicfoundation/hardhat-network-helpers
yarn add --dev @nomicfoundation/hardhat-network-helpers

# Usage

To use a network helper, simply import it where you want to use it:

TypeScript
JavaScript
import { mine } from "@nomicfoundation/hardhat-network-helpers";

async function main() {
  // instantly mine 1000 blocks
  await mine(1000);
}
const { mine } = require("@nomicfoundation/hardhat-network-helpers");

async function main() {
  // instantly mine 1000 blocks
  await mine(1000);
}

Since this is not a Hardhat plugin, you don’t need to import the whole package in your config. You can simply import each specific helper function where you need to use them.

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