viem

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires viem.

What problem does it solve? AI agents and developers frequently confuse viem with ethers.js patterns, producing code with wrong types (BigNumber instead of bigint), missing chain configuration, and unsafe transactions sent without simulation. This Skill provides correct, current viem patterns for reading blockchain state, writing transactions, and handling errors on any EVM chain. ## Core Features & Use Cases - Type-Safe Contract Interaction: Read and write contracts with full ABI type inference using as const assertions, readContract, simulateContract, and writeContract. - Client & Transport Architecture: Configure PublicClient, WalletClient, and TestClient with HTTP, WebSocket, and fallback transports across 50+ built-in chain definitions. - Utilities & Error Handling: Convert values with parseEther/formatUnits, encode and decode ABI data, and walk structured error chains to extract revert reasons. - Use Case: Build a dApp backend that checks ERC-20 balances via multicall, simulates a token approval, executes the write, waits for the receipt, and decodes any revert reason if the transaction fails. ## Quick Start Use the viem skill to create a public client on 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?

Create a PublicClient with createPublicClient, passing an explicit chain and http transport, then call readContract with the contract address, ABI, function name, and args. Define the ABI with an as const assertion so return values and arguments are fully typed.

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 via simulateContract.

How do I send a transaction safely with viem?

Call simulateContract first to catch reverts without spending gas, then pass the returned request object to walletClient.writeContract. Afterward, call waitForTransactionReceipt and check that receipt.status is not reverted before treating the transaction as successful.

Does viem support batching multiple contract reads?

Yes, client.multicall batches multiple read calls into a single RPC request through the Multicall3 contract. By default allowFailure is true, so each result includes a status field; set allowFailure to false to throw on the first failure.

Why does JSON.stringify fail on viem return values?

viem returns bigint values, which JSON.stringify cannot serialize natively. Pass a replacer function that converts bigint values to strings, or convert values with toString or formatUnits before serializing.

How do I handle contract revert errors in viem?

Catch the error, check it is an instance of BaseError, then use err.walk with a predicate to find ContractFunctionRevertedError in the cause chain. The revert error exposes data.errorName and data.args for custom Solidity errors, or a reason string for require-style reverts.