Skip to main content

Test client

anvil.testClient is an AnvilTestClient<TAccount>: a viem test client (mode: "anvil") with public, wallet and anvil extra actions, bound to the node's chain. No response cache, 25 ms polling, and eth_chainId answered locally.

LayerUse it for
anvil.testClienteverything viem can do: test actions, reads, simulations, watchers, writes, signing
anvil.cheatsfluent chains of state changes (cheats)
anvil.* helpersaccounts with keys, receipts, snapshots, state files (StartedAnvilContainer)

With a default account, actions compile without account.

viem test actions​

viem actionanvil RPCcheats stepNotes
dropTransactionanvil_dropTransactiondropTransaction()
dumpStateanvil_dumpState–also anvil.dumpState() / dumpStateToFile()
getAutomineanvil_getAutomine–also anvil.getAutomine()
getTxpoolContenttxpool_content–pending / queued transactions by sender and nonce
getTxpoolStatustxpool_status–{ pending, queued } counts
impersonateAccountanvil_impersonateAccountimpersonate()also anvil.impersonate() / withImpersonation()
increaseTimeevm_increaseTimeincreaseTime()durations in cheats / anvil.increaseTime()
inspectTxpooltxpool_inspect–human-readable summary
loadStateanvil_loadStateloadState()merges a dump; discards snapshots
mineanvil_minemine()blocks, optional interval
removeBlockTimestampIntervalanvil_removeBlockTimestampIntervalremoveBlockTimestampInterval()
resetanvil_resetreset()fixed version, see anvil extras
revertevm_revert–strict: throws SNAPSHOT_NOT_FOUND
sendUnsignedTransactioneth_sendUnsignedTransaction–send as any funded address
setAutomineevm_setAutominesetAutomine()
setBalanceanvil_setBalancesetBalance() / setBalanceEther()wei / Ether
setBlockGasLimitevm_setBlockGasLimitsetBlockGasLimit()
setBlockTimestampIntervalanvil_setBlockTimestampIntervalsetBlockTimestampInterval()fixed seconds between blocks
setCodeanvil_setCodesetCode()runtime bytecode ("etch")
setCoinbaseanvil_setCoinbasesetCoinbase()
setIntervalMiningevm_setIntervalMiningsetIntervalMining()0 turns it off
setLoggingEnabledanvil_setLoggingEnabledsetLoggingEnabled()
setMinGasPriceanvil_setMinGasPricesetMinGasPrice()pre-London hardforks only
setNextBlockBaseFeePerGasanvil_setNextBlockBaseFeePerGassetNextBlockBaseFeePerGas()
setNextBlockTimestampevm_setNextBlockTimestampsetNextBlockTimestamp()seconds, bigint or Date in cheats
setNonceanvil_setNoncesetNonce()
setRpcUrlanvil_setRpcUrlsetRpcUrl()fork RPC URL
setStorageAtanvil_setStorageAtsetStorageAt()a bigint value is encoded in cheats
snapshotevm_snapshot–also anvil.snapshot() / checkpoint()
stopImpersonatingAccountanvil_stopImpersonatingAccountstopImpersonating()

Public and wallet actions​

All of viem's: readContract, simulateContract, multicall, getLogs, writeContract, signTypedData, …

Tasks: Act as multiple users, Configure the test client.