LocalNodeManager Class
Manages the lifecycle and state of a local Anvil Ethereum node for testing. Handles dynamic port allocation, process management, and exposes a rich set of methods for manipulating the blockchain state.Constructor
NodeConfig
Optional node configuration options. See Configuration for details.
Properties
number
The allocated port number, or -1 if not started.
string
The RPC URL for the running node (e.g.,
http://localhost:12345).Lifecycle Methods
start()
stop()
getPort()
null if not started.
State Management Methods
snapshot()
revert().
revert()
string
required
The ID returned from
snapshot()reset()
bigint
Optional block number to reset to (when in fork mode)
Mining Methods
mine()
number
default:"1"
Number of blocks to mine
setAutomine()
boolean
required
Whether to enable automatic mining
Time Manipulation Methods
setNextBlockTimestamp()
number
required
Unix timestamp in seconds
increaseTime()
number
required
Number of seconds to advance
setTime()
number
required
Unix timestamp in seconds
Account Management Methods
getAccounts()
setBalance()
string
required
The address to modify
bigint
required
The new balance in wei
setNonce()
string
required
The address to modify
number
required
The new nonce value
impersonateAccount()
string
required
The address to impersonate
stopImpersonatingAccount()
string
required
The address to stop impersonating
Contract Methods
setCode()
string
required
The contract address
string
required
The contract bytecode (hex string)
setStorageAt()
string
required
The contract address
string
required
The storage slot (hex string)
string
required
The value to store (hex string)
Gas Configuration Methods
setNextBlockBaseFeePerGas()
bigint
required
The base fee in wei
setMinGasPrice()
bigint
required
The minimum gas price in wei
Network Methods
setChainId()
number
required
The new chain ID
Next Steps
- Learn about configuration options