API Reference

The client factories and action families that make up viem's public surface.

Path: api-reference

Third-party documentation. This is independently authored analysis of the public Viem codebase — not the official docs, and not reviewed or endorsed by the Viem team.

API Reference

Viem's surface area is intentionally small: two client factories, action families per client, and a utilities module.

Client factories

  • createPublicClient() — read-side client.
  • createWalletClient() — write-capable client.
  • createTestClient() — Anvil/Ganache-style dev-node control (mining, snapshots, impersonation).

Core actions

  • Chain state: getBlock, getTransaction, getTransactionReceipt, getBlockNumber, getGasPrice.
  • Accounts: getBalance, getNonce, getBytecode, getStorageAt.
  • Contracts: readContract, simulateContract, writeContract, watchContractEvent.
  • Writes: sendTransaction, sendRawTransaction, waitForTransactionReceipt.

Utilities

  • Units: parseEther, parseUnits, formatEther, formatUnits.
  • ABI: encodeFunctionData, decodeFunctionResult, encodeEventTopics, decodeErrorResult.
  • Data: toHex/fromHex, isAddress/getAddress (checksummed), keccak256, hashMessage.

Accounts

privateKeyToAccount, generateMnemonic, mnemonicToAccount — all returning the shared account interface (sign, signMessage, signTypedData, address).

Interface

Interface
typescript
function createPublicClient({ chain, transport, account? }): PublicClient
function createWalletClient({ chain, transport, account }): WalletClient
 
// Read actions (PublicClient)
client.getBlockNumber(): bigint
client.getBalance({ address }): bigint
client.readContract({ address, abi, functionName, args? })
client.watchContractEvent({ address, abi, eventName, onLogs })
 
// Write actions (WalletClient)
wallet.sendTransaction({ to, value?, data? }): Hash
wallet.writeContract({ address, abi, functionName, args? }): Hash
wallet.signMessage({ message }): Hex
 
// Utilities
parseEther('1.5'): bigint // ether string -> wei bigint
formatUnits(value, decimals): string
encodeFunctionData / decodeFunctionResult
 
STATUSinterface