Skip to main content

Overview

Anvil-specific RPC methods for controlling local test networks. These methods enable advanced testing scenarios like state manipulation, time travel, and account impersonation.

Snapshot & Revert

evm_snapshot

Creates a snapshot of the current blockchain state.

evm_revert

Reverts the blockchain state to a previous snapshot.
Example: Test rollback

Time Manipulation

evm_mine

Mines one or more blocks.

evm_increaseTime

Fast-forwards time by the specified number of seconds.

evm_setNextBlockTimestamp

Sets the timestamp of the next block.

evm_setBlockGasLimit

Sets the block gas limit.
Example: Time-based testing

Account Impersonation

anvil_impersonateAccount

Start impersonating an account (send transactions without private key).

anvil_stopImpersonatingAccount

Stop impersonating an account.
Example: Impersonation

State Manipulation

anvil_setBalance

Sets the balance of an account.

anvil_setCode

Sets the bytecode at an address.

anvil_setNonce

Sets the nonce of an account.

anvil_setStorageAt

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

Mining Control

evm_setAutomine

Enables or disables automatic mining of blocks.

evm_setIntervalMining

Sets the mining interval in seconds (0 disables).
Example: Manual mining

Common Patterns

Test Isolation

Fork Testing

Gas Optimization Testing

See Also