Getting Started
Get started with viem in just a few lines of code.
Overview
viem is a TypeScript interface for Ethereum that provides low-level stateless primitives for interacting with Ethereum. viem is focused on developer experience, stability, bundle size, and performance:
- Developer experience Automatic type safety and inference, comprehensive documentation, composable APIs.
- Stability Test suite runs against forked Ethereum networks, complete test coverage.
- Bundle size Tree-shakable lightweight modules.
- Performance Optimized encoding/parsing, async tasks only when necessary.
You can learn more about the rationale behind the project in the Why viem section.
Installation
npm
npm i viemQuick Start
1. Set up your Client & Transport
Firstly, set up your Client with a desired Transport & Chain.
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
 
const client = createPublicClient({ 
  chain: mainnet, 
  transport: http(), 
}) 2. Consume Actions
Now that you have a Client set up, you can now interact with Ethereum and consume Actions!
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
 
const client = createPublicClient({
  chain: mainnet,
  transport: http(),
})
 
const blockNumber = await client.getBlockNumber() 
