Getting Started
Installation
bash
npm i viem
bash
pnpm i viem
bash
yarn add viem
Quick Start
1. Set up your Client & Transport
Firstly, set up your Client with a desired Transport & Chain.
tsx
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
INFO
In a production app, it is highly recommended to pass through your authenticated RPC provider URL (Alchemy, Infura, Ankr, etc). If no URL is provided, viem will default to a public RPC provider. Read more.
2. Consume Actions!
Now that you have a Client set up, you can now interact with Ethereum and consume Actions!
tsx
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { getBlockNumber } from 'viem/public'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const blockNumber = await getBlockNumber(client)