Skill — Copyable reference implementation. Use as-is or customize. See Skills Philosophy.
Viem-style PublicClient
This Skill demonstrates how to build a viem-compatible PublicClient using Voltaire primitives. The implementation follows viem’s architecture patterns while leveraging Voltaire’s type-safe primitives.Overview
The PublicClient provides access to public Ethereum JSON-RPC methods like fetching blocks, transactions, balances, and making calls. Key features:- Transport abstraction - HTTP, WebSocket, or custom transports
- Extend pattern - Composable client extension for custom actions
- Type safety - Full TypeScript types for all methods
- Caching - Built-in request caching with configurable TTL
Quick Start
Architecture
Client Structure
Transport Layer
The transport layer handles JSON-RPC communication:Extend Pattern
Extend the client with custom actions:API Reference
createPublicClient
Creates a PublicClient with public actions.| Name | Type | Description |
|---|---|---|
| chain | Chain | Chain configuration (optional) |
| transport | TransportFactory | Transport factory (required) |
| cacheTime | number | Cache duration in ms (default: pollingInterval) |
| pollingInterval | number | Block polling interval (default: blockTime/2) |
| key | string | Client key (default: ‘public’) |
| name | string | Client name (default: ‘Public Client’) |
Public Actions
getBlockNumber
Returns the current block number.getBalance
Returns the balance of an address.getBlock
Returns block information.call
Executes a call without creating a transaction.estimateGas
Estimates gas for a transaction.getTransaction
Returns transaction by hash.getTransactionReceipt
Returns transaction receipt.getLogs
Returns logs matching filter.getCode
Returns contract bytecode.getStorageAt
Returns storage at slot.getTransactionCount
Returns transaction count (nonce).getChainId
Returns chain ID.getGasPrice
Returns current gas price.Chain Definitions
Pre-configured chain definitions:Error Handling
The client throws typed errors:Testing
Run the test suite:Implementation Notes
Caching
Block number is cached to reduce RPC calls:Retry Logic
HTTP transport automatically retries on network errors (not RPC errors):Polling Interval
Polling interval is derived from chain block time:- Mainnet (12s blocks): 4000ms polling
- Arbitrum (250ms blocks): 500ms polling
File Structure
Next Steps
Future enhancements:- readContract - ABI-aware contract reads
- multicall - Batched contract calls
- watchBlockNumber - Block number subscription
- watchBlocks - Block subscription
- WebSocket transport - Real-time subscriptions
- ENS support - Name resolution

