> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Getting Started

## Overview

Viem is a TypeScript interface for Ethereum. It provides typed, composable building blocks for
Clients, Transports, Accounts, Actions, and protocol utilities.

This guide installs Viem, creates a [Client](/docs/clients), and reads the latest block number. See
[Why Viem](/docs/why-viem) for the design principles behind the library.

## Agent Prompt

Paste this prompt into your coding agent:

```prompt
Read v3.viem.sh and help me build my project with Viem. Add https://v3.viem.sh/api/mcp as an MCP server. Refer to https://v3.viem.sh/docs/v2-migration when migrating from Viem v2.
```

## Setup

::::steps
### Install Viem

Install Viem with your package manager.

:::code-group
```bash [pnpm]
pnpm add viem@next
```

```bash [npm]
npm install viem@next
```

```bash [Yarn]
yarn add viem@next
```

```bash [Bun]
bun add viem@next
```
:::

See [Installation](/docs/installation) for Deno, CDN, and preview-release options.

### Create a Client

Create a [Client](/docs/clients) with a [Chain](/docs/chains) and an HTTP
[Transport](/docs/transports/http), then extend it with
[`publicActions`](/docs/actions/public).

```ts twoslash filename="viem.config.ts"
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())
```

:::info
`http()` uses the Chain's public RPC URL. Use an authenticated RPC URL in production to avoid
public rate limits.
:::

### Read the Latest Block Number

Call [`client.block.getNumber`](/docs/actions/public/block/getNumber) to read the latest block
number.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const blockNumber = await client.block.getNumber()
// @log: 22_000_000n
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())
```
:::
::::

## Next Steps

<Cards>
  <Card title="Installation" description="Install Viem across package managers and runtime environments." icon="lucide:package" to="/docs/installation" />

  <Card title="Clients" description="Compose Chains, Transports, Accounts, and Actions." icon="lucide:boxes" to="/docs/clients" />

  <Card title="Actions" description="Read chain state, connect wallets, and send transactions." icon="lucide:zap" to="/docs/actions" />

  <Card title="Chains" description="Use a built-in Chain or define your own." icon="lucide:blocks" to="/docs/chains" />
</Cards>
