Skill — Copyable reference implementation. Use as-is or customize. See Skills Philosophy.
Viem Test Client
A copyable implementation of viem’s test client abstraction for local test nodes.Overview
This Skill provides a complete viem-compatible test client including:createTestClient- Factory returning test client with bound actionsmine- Mine blockssetBalance- Set account balancesetCode- Set contract bytecodesetStorageAt- Set storage slotsetNonce- Set account nonceimpersonateAccount- Send transactions as any addressstopImpersonatingAccount- Stop impersonationsnapshot/revert- Save and restore EVM stateincreaseTime/setNextBlockTimestamp- Time manipulationreset- Reset fork statedumpState/loadState- Serialize and restore state
Quick Start with Anvil
Snapshot and Revert
Save and restore EVM state:Account Impersonation
Send transactions from any address without the private key:Time Manipulation
Control block timestamps for testing time-dependent contracts:State Manipulation
Modify accounts directly:Fork Management
Reset and manage forked state:State Serialization
Save and restore entire state:Automine Control
Control automatic block mining:Mode Differences
Different test nodes use different RPC methods:
The test client handles these differences automatically based on the
mode parameter.
Hardhat Example
Ganache Example
Files
Copy these files into your codebase:createTestClient.js- Main factory functionmine.js- Mine blockssetBalance.js- Set account balancesetCode.js- Set contract codesetStorageAt.js- Set storage slotsetNonce.js- Set account nonceimpersonateAccount.js- Impersonate addressstopImpersonatingAccount.js- Stop impersonatingsnapshot.js- Create EVM snapshotrevert.js- Revert to snapshotincreaseTime.js- Advance timesetNextBlockTimestamp.js- Set next block timestampdropTransaction.js- Remove tx from mempoolreset.js- Reset forkdumpState.js- Serialize stateloadState.js- Load statesetAutomine.js- Control automineTestClientTypes.ts- TypeScript type definitionserrors.ts- Custom error classesindex.ts- Module exports
Differences from Viem
This implementation:- Uses Voltaire’s
AddressandHexprimitives - Requires explicit provider (no transport abstraction)
- Does not include chain configuration
- Simplified error handling
- Transport abstraction (HTTP, WebSocket, IPC)
- Chain configuration with native currency
- Request batching
- Retry logic for RPC calls

