# 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. ## Install Save in your project root: # Viem — TypeScript Interface for Ethereum ## Quick Use ```bash npm install viem # In your script # import { createPublicClient, http } from 'viem'; # import { mainnet } from 'viem/chains'; # const client = createPublicClient({ chain: mainnet, transport: http() }); # const block = await client.getBlockNumber(); ``` ## 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 - https://github.com/wevm/viem - https://viem.sh --- Source: https://tokrepo.com/en/workflows/asset-b5e57160 Author: AI Open Source