Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsMay 14, 2026·3 min de lecture

Viem — TypeScript Interface for Ethereum

Viem is a modern TypeScript library for interacting with the Ethereum blockchain. It provides composable, type-safe modules for public client reads, wallet actions, contract interactions, ABI encoding, and ENS resolution. Viem is the low-level transport layer that powers Wagmi and has become the successor to ethers.js for many TypeScript-first teams.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Viem
Commande CLI universelle
npx tokrepo install b5e57160-4f90-11f1-9bc6-00163e2b0d79

Introduction

Viem is a TypeScript-first Ethereum library built by the wevm team (the creators of Wagmi). It takes a composable, tree-shakeable approach where each action is an independent function rather than a method on a large class. Viem replaces ethers.js and web3.js for developers who want strict TypeScript safety and minimal bundle sizes.

What Viem Does

  • Reads chain state through a Public Client with actions like getBalance, getBlock, and readContract
  • Signs and sends transactions via a Wallet Client connected to a local key or browser wallet
  • Encodes and decodes ABI data, function selectors, event logs, and EIP-712 typed data
  • Resolves ENS names and supports reverse resolution
  • Provides chain definitions for 100+ EVM networks out of the box

Architecture Overview

Viem is organized around three client types: Public Client (read-only RPC calls), Wallet Client (signing and sending transactions), and Test Client (Anvil/Hardhat node manipulation). Each client accepts a chain definition and a transport (HTTP, WebSocket, IPC, or custom). Actions are standalone functions that take a client as the first argument, making them composable and tree-shakeable. ABI types are fully inferred at the TypeScript level, so contract method names, argument types, and return types are checked at compile time.

Self-Hosting & Configuration

  • Install with npm install viem and import only the modules you need
  • Create clients with createPublicClient or createWalletClient specifying chain and transport
  • Use viem/chains to import pre-configured chain objects or define custom ones
  • For browser DApps, use custom(window.ethereum) as the transport with a Wallet Client
  • Configure batch JSON-RPC via the batch option on the HTTP transport for reduced latency

Key Features

  • Full TypeScript inference on contract reads and writes based on ABI literals
  • Tree-shakeable architecture keeps production bundles small
  • Built-in multicall batching for efficient on-chain reads
  • Human-readable ABI support alongside standard JSON ABIs
  • Zero dependencies beyond TypeScript types

Comparison with Similar Tools

  • ethers.js — Class-based API with a larger footprint; Viem is functional, tree-shakeable, and has stricter types
  • web3.js — Plugin-oriented legacy library; Viem offers modern TypeScript ergonomics
  • Wagmi — React hooks layer built on Viem; Viem is the framework-agnostic core
  • Alloy — Rust equivalent by the same ecosystem; Viem serves the TypeScript/JavaScript side

FAQ

Q: Is Viem a replacement for ethers.js? A: Many teams adopt Viem as a modern alternative. It offers better TypeScript inference and smaller bundles, though ethers.js remains widely used.

Q: Does Viem work in the browser? A: Yes. Viem works in browsers, Node.js, Deno, and Bun with no environment-specific dependencies.

Q: How does ABI type inference work? A: When you pass an ABI as a const assertion, Viem infers function names, argument types, and return types at the TypeScript level, catching errors before runtime.

Q: Can I use Viem without Wagmi? A: Yes. Viem is a standalone library. Wagmi is an optional React/Vue layer built on top of it.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires