Skip to main content

Overview

Hardhat Network-specific RPC methods for controlling test environments. These methods provide similar functionality to Anvil but with Hardhat-specific naming conventions.

Network Control

hardhat_reset

Resets the fork to a fresh state or a specific block.
Example: Fork reset

State Manipulation

hardhat_setBalance

Sets the balance of an account.

hardhat_setCode

Sets the bytecode at an address.

hardhat_setNonce

Sets the nonce of an account.

hardhat_setStorageAt

Sets the storage value at a specific slot.
Example: Test account setup

Account Impersonation

hardhat_impersonateAccount

Start impersonating an account.

hardhat_stopImpersonatingAccount

Stop impersonating an account.
Example: Impersonate mainnet account

Mining

hardhat_mine

Mines one or more blocks.
Example: Mine to trigger time-based logic

Common Patterns

Forking Mainnet

Test Setup

State Manipulation for Testing

Hardhat vs Anvil

Both Hardhat and Anvil provide similar testing functionality with different naming:

See Also