> **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.

# 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

[pkg.pr.new](https://pkg.pr.new) publishes packages for pull requests and commits. Copy an install
URL from the pull request or workflow output.

You can also replace `123` below with a pull request number or short commit ID.

:::code-group
```bash [pnpm]
pnpm add https://pkg.pr.new/viem@123
```

```bash [npm]
npm install https://pkg.pr.new/viem@123
```

```bash [Yarn]
yarn add https://pkg.pr.new/viem@123
```

```bash [Bun]
bun add https://pkg.pr.new/viem@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).
