viem

Interact with Ethereum and EVM chains using type-safe TypeScript clients for reads, writes, and ABI encoding.

6|20|Updated Mar 14, 2026
One-click install
npx skills add https://github.com/andresdefi/cryptoskills --skill viem-andresdefi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: viem
Source: https://github.com/andresdefi/cryptoskills/tree/main/skills/viem
Command: npx skills add https://github.com/andresdefi/cryptoskills --skill viem-andresdefi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires viem.

What problem does it solve? AI agents and developers frequently produce outdated ethers.js patterns, hallucinated contract interactions, and type-unsafe blockchain code. This Skill provides accurate, current viem patterns for reading blockchain state, sending transactions, and interacting with smart contracts on Ethereum and EVM-compatible chains with full TypeScript type safety. ## Core Features & Use Cases - Typed Contract Interaction: Read and write to smart contracts with end-to-end type inference from ABIs using as const assertions, including the simulate-then-execute pattern that catches reverts before spending gas. - Client Architecture: Configure PublicClient for reads, WalletClient for writes, and TestClient for local nodes, with HTTP, WebSocket, and fallback transports across 50+ built-in chain definitions. - Batching and Utilities: Batch reads via Multicall3, encode/decode ABI calldata, convert between wei/gwei/ether with bigint, and handle errors through the BaseError walk pattern. - Use Case: Build a dApp backend that checks ERC-20 balances across multiple tokens in one RPC call, approves a spender only when allowance is insufficient, and executes a swap with gas estimation and revert handling. ## Quick Start Ask the agent to create a viem public client for Ethereum mainnet and read the USDC balance of a given wallet address.

Frequently Asked Questions about viem

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I read a smart contract with viem in TypeScript?

Use createPublicClient with a chain and transport, then call readContract with the contract address, ABI, function name, and args. Define the ABI with an as const assertion so TypeScript infers argument and return types automatically.

What is the difference between viem and ethers.js?

viem uses native bigint instead of BigNumber, splits functionality into PublicClient and WalletClient instead of Provider and Signer, and requires explicit chain and transport configuration. ABIs need as const assertions for type inference, and simulation is separated from execution.

How do I send a transaction with viem walletClient?

Create a WalletClient with an account, chain, and transport, then call sendTransaction for ETH transfers or simulateContract followed by writeContract for contract calls. Always simulate first to catch reverts before spending gas, then check the receipt status.

Does viem support chains other than Ethereum mainnet?

Yes, viem ships definitions for 50+ chains including Arbitrum, Optimism, Base, Polygon, zkSync, and Scroll, importable from viem/chains. For unsupported networks, use defineChain to specify the chain ID, RPC URLs, native currency, and block explorer.

Why does viem throw ContractFunctionRevertedError?

This error means the contract call reverted on-chain, usually from insufficient balance, missing approval, or invalid arguments. Catch it via err.walk() on a BaseError to access the decoded custom error name and arguments from revertError.data.

How do I batch multiple contract reads into one RPC call?

Use client.multicall with an array of contract call configurations, which routes through the Multicall3 contract in a single RPC round-trip. By default allowFailure is true, so each result includes a status field indicating success or failure.