Thanks for your interest in contributing to viem! Please take a moment to review this document before submitting a pull request.
If you want to contribute, but aren't sure where to start, you can create a new discussion.
If you are contributing to add a new chain to viem/chains
, please read the Chains section.
Note
Please ask first before starting work on any significant new features.
It's never a fun experience to have your pull request declined after investing time and effort into a new feature. To avoid this from happening, we request that contributors create a feature request to first discuss any API changes or significant new ideas.
This guide is intended to help you get started with contributing. By following these steps, you will understand the development process and workflow.
- Cloning the repository
- Installing Node.js and Bun
- Installing Foundry
- Installing dependencies
- Running the test suite
- Writing documentation
- Submitting a pull request
- Versioning
To start contributing to the project, clone it to your local machine using git:
git clone https://github.com/wevm/viem.git --recurse-submodules
Or the GitHub CLI:
gh repo clone wevm/viem -- --recurse-submodules
wagmi uses Bun workspaces to manage multiple projects. You need to install Node.js v18 or higher and Bun v1 or higher.
You can run the following commands in your terminal to check your local Node.js and Bun versions:
node -v
bun -v
If the versions are not correct or you don't have Node.js or Bun installed, download and follow their setup instructions:
- Install Node.js using fnm or from the official website
- Install Bun
viem uses Foundry for testing. We run a local Anvil instance against a forked Ethereum node, where we can also use tools like Forge to deploy test contracts to it.
Install Foundry using the following command:
curl -L https://foundry.paradigm.xyz | bash
Once in the project's root directory, run the following command to install the project's dependencies:
bun install
After the install completes, Bun links packages across the project for development and git hooks are set up.
First, add the following to your environment (recommended to use direnv
):
VITE_ANVIL_FORK_URL=https://rpc
VITE_ANVIL_BLOCK_TIME=1
VITE_ANVIL_BLOCK_NUMBER=16280770
VITE_NETWORK_TRANSPORT_MODE=http
VITE_ANVIL_PORT=8545
VITE_ANVIL_FORK_URL
can be for any RPC service provider (e.g. Alchemy or Infura) for the mainnet. Now you are ready to run the tests!
bun run test
— runs tests in watch mode
Sometimes there may be some tests which fail unexpectedly – you can press f
to rerun them and they should pass.
When adding new features or fixing bugs, it's important to add test cases to cover the new/updated behavior.
Documentation is crucial to helping developers of all experience levels use viem. viem uses Vocs and Markdown for the documentation site (located at site
). To start the site in dev mode, run:
bun run docs:dev
Try to keep documentation brief and use plain language so folks of all experience levels can understand. If you think something is unclear or could be explained better, you are welcome to open a pull request.
When you're ready to submit a pull request, you can follow these naming conventions:
- Pull request titles use the Imperative Mood (e.g.,
Add something
,Fix something
). - Changesets use past tense verbs (e.g.,
Added something
,Fixed something
).
When you submit a pull request, GitHub will automatically lint, build, and test your changes. If you see an ❌, it's most likely a bug in your code. Please, inspect the logs through the GitHub UI to find the cause.
When adding new features or fixing bugs, we'll need to bump the package versions. We use Changesets to do this.
Note
Only changes to the codebase that affect the public API or existing behavior (e.g. bugs) need changesets.
Each changeset defines which package(s) should be published and whether the change should be a major/minor/patch release, as well as providing release notes that will be added to the changelog upon release.
To create a new changeset, run bun run changeset
. This will run the Changesets CLI, prompting you for details about the change. You’ll be able to edit the file after it’s created — don’t worry about getting everything perfect up front.
Even though you can technically use any markdown formatting you like, headings should be avoided since each changeset will ultimately be nested within a bullet list. Instead, bold text should be used as section headings.
If your PR is making changes to an area that already has a changeset (e.g. there’s an existing changeset covering theme API changes but you’re making further changes to the same API), you should update the existing changeset in your PR rather than creating a new one.
If you wish to contribute to add an additional Chain to the viem/chains
entrypoint, there are a few requirements to note before submitting a pull request.
- Must haves:
- a unique Chain ID (
id
), - a human-readable name (
name
), - an internal network label (
network
), - a native currency reference (
nativeCurrency
), - a public, credible RPC URL (
rpcUrls.default
&rpcUrls.public
)
- a unique Chain ID (
- Nice to haves
- a block explorer (
blockExplorers
) - a multicall3 contract (
contracts.multicall3
)- this contract must be verified, and must match the bytecode of the multicall3 contract.
- a block explorer (
- Optional
- ENS registry contract (
contracts.ensRegistry
) - testnet flag (
testnet
)
- ENS registry contract (
If your Chain satisfies the necessary criteria, you may submit a pull request for consideration. If your pull request does not satisfy the criteria, it will be closed.
The Chain
type has a number of important attributes, and you may get stuck on what to add to these. Most of these attributes exist within the ethereum-lists/chains
repository.
id
: The Chain ID for the network. This can be found by typing the network name into ChainList. Example: "Ethereum Mainnet" has a Chain ID of1
.name
: A human readable name for the network. Example: "Binance Smart Chain Mainnet"nativeCurrency
: The native currently of the network. Found fromethereum-lists/chains
.rpcUrls
: A set of RPC URLs for the chain. Found fromethereum-lists/chains
.blockExplorers
: A set of block explorers for the chain. Found fromethereum-lists/chains
.contracts
: A set of deployed contracts for the Chain.multicall3
is optional, but it's address is most likely0xca11bde05977b3631167028862be2a173976ca11
– you can find the deployed block number on the block explorer. Found frommds1/multicall
.ensRegistry
is optional – not all Chains have an ENS Registry. See ENS Deployments for more info.ensUniversalResolver
is optional – not all Chains have an ENS Universal Resolver.
testnet
: Whether or not the Chain is a testnet.
Read the Basic Guide to contributing to set up your environment.
Create a file for your chain in src/chains/definitions/
.
Example:
src/
├─ chains/
│ ├─ definitions/
│ │ ├─ avalanche.ts
│ │ ├─ ...
+│ │ ├─ example.ts
│ │ ├─ ...
│ │ ├─ zora.ts
│ ├─ index.ts
Define your chain data in defineChain
.
Example:
// src/chains/definitions/example.ts
import { defineChain } from '../../utils/chain/defineChain.js'
export const mainnet = /*#__PURE__*/ defineChain({
id: 1,
name: 'Example Chain',
nativeCurrency: { name: 'Example', symbol: 'ETH', decimals: 18 },
rpcUrls: {
default: {
http: ['https://example.com'],
},
},
blockExplorers: {
default: {
name: 'Etherscan',
url: 'https://etherscan.io',
apiUrl: 'https://api.etherscan.io/api',
},
},
contracts: {
multicall3: {
address: '0xca11bde05977b3631167028862be2a173976ca11',
blockCreated: 69420,
},
},
})
Export the chain in src/chains/index.ts
.
Example:
export type { Chain } from '../types/chain.js'
export { arbitrum } from './definitions/arbitrum.js'
...
+export { example } from './definitions/example.js'
...
export { zora } from './definitions/zora.js'
Add a patch
changeset with the description "Added <your chain here> chain."
.
> bun run changeset
What kind of change is this for viem?
+ patch
Please enter a summary for this change
+ Added Example chain.
Now you are ready to open your Pull Request.