Skill — Copyable reference implementation. Use as-is or customize. See Skills Philosophy.
Viem Contract Abstraction
A copyable implementation of viem’s contract abstraction patterns using Voltaire primitives.Overview
This Skill provides a complete viem-compatible contract abstraction including:getContract- Factory returning typed contract instance with proxied methodsreadContract- Read view/pure functions via eth_callwriteContract- Execute state-changing functions via eth_sendTransactionsimulateContract- Dry-run write functions to validate and get return valuesestimateContractGas- Estimate gas for write operationswatchContractEvent- Subscribe to contract events via polling
Quick Start
Using getContract
Standalone Actions
readContract
Call view/pure functions without needing a contract instance:writeContract
Execute state-changing functions:simulateContract
Validate a write operation before executing:estimateContractGas
Estimate gas before writing:watchContractEvent
Subscribe to contract events:Type Inference
The abstraction provides full type inference from your ABI:Error Handling
All actions wrap errors in specific error classes:Split Clients
You can provide separate public and wallet clients:Files
Copy these files into your codebase:getContract.js- Main factory functionreadContract.js- Read actionwriteContract.js- Write actionsimulateContract.js- Simulation actionestimateContractGas.js- Gas estimation actionwatchContractEvent.js- Event watching actionViemContractTypes.ts- TypeScript type definitionserrors.ts- Custom error classesindex.ts- Module exports
Differences from Viem
This implementation:- Uses Voltaire’s
Abiprimitive for encoding/decoding - Uses polling-only event watching (no WebSocket support)
- Does not include
createContractEventFilterorgetContractEvents - Simplified parameter handling
- WebSocket subscription support for events
- Filter-based event watching
- Request batching
- Retry logic for RPC calls

