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

# Installation

Install Viem with your package manager for version locking, type declarations, and tree shaking.
For small prototypes, you can also load Viem from an ESM CDN.

## 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
```

```bash [Deno]
deno add npm:viem@next
```
:::

The `npm:` package specifier selects the npm registry explicitly. See the
[`deno add` reference](https://docs.deno.com/runtime/reference/cli/add/) for other options.

## CDN

Use an ESM-compatible CDN such as [esm.sh](https://esm.sh) when a package manager is not
available. Pin the Viem major version in the URL to avoid unexpected breaking changes.

```html
<script type="module">
  import { Actions, Client, http } from 'https://esm.sh/viem@next'
  import { mainnet } from 'https://esm.sh/viem@next/chains'

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

  const blockNumber = await Actions.block.getNumber(client)
  console.log(blockNumber)
</script>
```

## Preview Releases

Commits to the [`v3` branch](https://github.com/wevm/viem/tree/v3) and maintainers' pull requests
into it publish to npm as prereleases. The `main-v3` dist-tag installs the latest commit to `v3`.
The `pr-<number>` dist-tag installs a pull request's latest commit until the pull request closes.

Each prerelease also stays installable by its exact version: `0.0.0-v3-<commit SHA>` for a commit
to `v3`, or `0.0.0-v3-pr-<number>-<short commit SHA>` for a pull request.

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

```bash [npm]
npm install viem@pr-123
```

```bash [Yarn]
yarn add viem@pr-123
```

```bash [Bun]
bun add viem@pr-123
```
:::

Preview packages are temporary and may contain unreviewed changes. Use a stable release in
production.

## Contribute from Source

Clone the repository with its submodules, then install and build the workspace with the versions
specified in `package.json`.

```bash
git clone https://github.com/wevm/viem.git --recurse-submodules
cd viem
pnpm install
pnpm build
```

Read the [contribution guide](https://github.com/wevm/viem/blob/main/.github/CONTRIBUTING.md)
before proposing an API or implementation change.

## Security

* Commit your lockfile, review dependency changes, and audit upgrades before deployment.
* Pin production versions and consider a package-manager release-age policy, such as
  [npm `min-release-age`](https://docs.npmjs.com/cli/v11/using-npm/config#min-release-age) or
  [pnpm `minimumReleaseAge`](https://pnpm.io/settings#minimumreleaseage).
* Avoid preview packages and floating CDN URLs in production. Restrict CDN origins with a
  [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP).
