Viem is a comprehensive, TypeScript-first interface for interacting with the Ethereum blockchain, designed to simplify dApp development. Currently stable at version 2.48.1, it exhibits a rapid release cadence with frequent patch updates and minor feature additions, reflecting active development. It provides robust abstractions over the JSON-RPC API, first-class APIs for smart contract interaction, and native BigInt support for handling large numbers without external libraries like BigNumber.js. Key differentiators include its deep integration with TypeScript for type inference from ABIs and EIP-712 typed data, strong alignment with official Ethereum terminology, and out-of-the-box support for local development environments such as Anvil, Hardhat, and Ganache. Viem aims to be a lightweight and highly type-safe alternative to other Ethereum libraries, focusing on developer experience and correctness through its strong type system.
npm install viemVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a public client, connect to the Ethereum mainnet using an HTTP transport, and fetch the current block number. It highlights Viem's core client creation pattern and basic data fetching.
Ensure your project uses ES Modules (`'type': 'module'` in `package.json`) and modern build tools. If CJS is unavoidable, consider dynamic `import()` or dual-package setups, though this adds complexity.
Upgrade your project's TypeScript version to `5.0.4` or newer: `npm install typescript@^5.0.4 -D` or `yarn add typescript@^5.0.4 -D`.
Update your `viem/tempo` configurations to use `withRelay` instead of `withFeePayer` for transaction relay functionality.
Implement robust error handling and backoff strategies at the application level. Consider upgrading your RPC provider plan or distributing requests across multiple providers if high throughput is critical.
Migrate your project to use ES Modules (set `"type": "module"` in `package.json` and use `import` statements) or use a bundler that correctly handles ESM-to-CJS transpilation.
Ensure `createPublicClient` or similar client creation functions are called with a valid `chain` object, e.g., `chain: mainnet` imported from `viem/chains`.
When serializing data that may contain BigInts (e.g., for logging or API responses), provide a custom replacer function to `JSON.stringify` that converts BigInts to strings: `JSON.stringify(obj, (key, value) => typeof value === 'bigint' ? value.toString() : value)`.
Install a compatible TypeScript version: `npm install typescript@^5.0.4 -D` or `yarn add typescript@^5.0.4 -D`.