Skip to content

Commit

Permalink
chore: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Aug 29, 2023
2 parents 72e4914 + cf4d5d8 commit 2492fbd
Show file tree
Hide file tree
Showing 147 changed files with 4,288 additions and 215 deletions.
196 changes: 180 additions & 16 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Thanks for your interest in contributing to viem! Please take a moment to review

If you want to contribute, but aren't sure where to start, you can create a [new discussion](https://github.com/wagmi-dev/viem/discussions).

If you are contributing to add a new chain to `viem/chains`, please read the [Chains section](#chains).

> **Note**
>
> **Please ask first before starting work on any significant new features.**
Expand All @@ -25,13 +27,9 @@ This guide is intended to help you get started with contributing. By following t
7. [Submitting a pull request](#submitting-a-pull-request)
8. [Versioning](#versioning)

<br>

---

<br>

## Cloning the repository
### Cloning the repository

To start contributing to the project, clone it to your local machine using git:

Expand All @@ -49,7 +47,9 @@ gh repo clone wagmi-dev/viem -- --recurse-submodules
<a href="#basic-guide">&uarr; back to top</a></b>
</div>

## Installing Node.js and pnpm
---

### Installing Node.js and pnpm

wagmi uses [pnpm workspaces](https://pnpm.io/workspaces) to manage multiple projects. You need to install **Node.js v18 or higher** and **pnpm v7 or higher**.

Expand All @@ -69,17 +69,25 @@ If the versions are not correct or you don't have Node.js or pnpm installed, dow
<a href="#basic-guide">&uarr; back to top</a></b>
</div>

## Installing Foundry
---

### Installing Foundry

viem uses [Foundry](https://book.getfoundry.sh/) for testing. We run a local [Anvil](https://github.com/foundry-rs/foundry/tree/master/anvil) instance against a forked Ethereum node, where we can also use tools like [Forge](https://book.getfoundry.sh/forge/) to deploy test contracts to it.
viem uses [Foundry](https://book.getfoundry.sh/) for testing. We run a local [Anvil](https://github.com/foundry-rs/foundry/tree/master/anvil) instance against a forked Ethereum node, where we can also use tools like [Forge](https://book.getfoundry.sh/forge/) to deploy test contracts to it.

Install Foundry using the following command:

```bash
curl -L https://foundry.paradigm.xyz | bash
```

## Installing dependencies
<div align="right">
<a href="#basic-guide">&uarr; back to top</a></b>
</div>

---

### Installing dependencies

Once in the project's root directory, run the following command to install the project's dependencies:

Expand All @@ -93,7 +101,9 @@ After the install completes, pnpm links packages across the project for developm
<a href="#basic-guide">&uarr; back to top</a></b>
</div>

## Running the test suite
---

### Running the test suite

First, add the following to your environment (recommended to use [`direnv`](https://github.com/direnv/direnv)):

Expand All @@ -104,19 +114,21 @@ VITE_ANVIL_BLOCK_NUMBER=16280770
VITE_NETWORK_TRANSPORT_MODE=http
```

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

- `pnpm 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.
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.

<div align="right">
<a href="#basic-guide">&uarr; back to top</a></b>
</div>

## Writing documentation
---

### Writing documentation

Documentation is crucial to helping developers of all experience levels use viem. viem uses [VitePress](https://github.com/vuejs/vitepress) and Markdown for the documentation site (located at [`site`](../site)). To start the site in dev mode, run:

Expand All @@ -130,7 +142,9 @@ Try to keep documentation brief and use plain language so folks of all experienc
<a href="#basic-guide">&uarr; back to top</a></b>
</div>

## Submitting a pull request
---

### Submitting a pull request

When you're ready to submit a pull request, you can follow these naming conventions:

Expand All @@ -143,9 +157,9 @@ When you submit a pull request, GitHub will automatically lint, build, and test
<a href="#basic-guide">&uarr; back to top</a></b>
</div>

<br>
---

## Versioning
### Versioning

When adding new features or fixing bugs, we'll need to bump the package versions. We use [Changesets](https://github.com/changesets/changesets) to do this.

Expand All @@ -161,6 +175,8 @@ Even though you can technically use any markdown formatting you like, headings s

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.

---

<br>

<div>
Expand All @@ -170,3 +186,151 @@ If your PR is making changes to an area that already has a changeset (e.g. there
<div align="right">
<a href="#advanced-guide">&uarr; back to top</a></b>
</div>

---

## Chains

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.

### Requirements

- **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`)
- **Nice to haves**
- a block explorer (`blockExplorers`)
- a [multicall3](https://www.multicall3.com/) contract (`contracts.multicall3`)
- this contract **must** be verified, and **must** match the bytecode of the [multicall3 contract](https://etherscan.io/address/0xca11bde05977b3631167028862be2a173976ca11#code).
- **Optional**
- other named RPC URLs (such as `rpcUrls.alchemy`, `rpcUrls.infura`, etc.)
- ENS registry contract (`contracts.ensRegistry`)
- testnet flag (`testnet`)

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.

### Attribute reference

The [`Chain` type](../src/types/chain.ts) 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](https://github.com/ethereum-lists/chains/tree/3fbd4eeac7ce116579634bd042b84e2b1d89886a/_data/chains).

- `id`: The Chain ID for the network. This can be found by typing the network name into [ChainList](https://chainlist.org/). Example: "Ethereum Mainnet" has a Chain ID of `1`.
- `name`: A human readable name for the network. Example: "Binance Smart Chain Mainnet"
- `network`: An internal network label. Example: "bsc"
- `nativeCurrency`: The native currently of the network. Found from [`ethereum-lists/chains`](https://github.com/ethereum-lists/chains/blob/3fbd4eeac7ce116579634bd042b84e2b1d89886a/_data/chains/eip155-56.json#L20-L24).
- `rpcUrls`: A set of RPC URLs for the chain. Found from [`ethereum-lists/chains`](https://github.com/ethereum-lists/chains/blob/3fbd4eeac7ce116579634bd042b84e2b1d89886a/_data/chains/eip155-56.json#L4-L18).
- `blockExplorers`: A set of block explorers for the chain. Found from [`ethereum-lists/chains`](https://github.com/ethereum-lists/chains/blob/3fbd4eeac7ce116579634bd042b84e2b1d89886a/_data/chains/eip155-56.json#L30-L36).
- `contracts`: A set of deployed contracts for the Chain.
- `multicall3` is optional, but it's address is most likely `0xca11bde05977b3631167028862be2a173976ca11` – you can find the deployed block number on the block explorer. Found from [`mds1/multicall`](https://github.com/mds1/multicall#multicall3-contract-addresses).
- `ensRegistry` is optional – not all Chains have an ENS Registry. See [ENS Deployments](https://docs.ens.domains/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.

### Adding a chain

#### 1. Read the contributing guide

Read the [Basic Guide](#basic-guide) to contributing to set up your environment.

#### 2. Create a chain file

Create a file for your chain in [`src/chains/definitions/`](../src/chains/definitions/).

Example:

```diff

src/
├─ chains/
│ ├─ definitions/
│ │ ├─ avalanche.ts
│ │ ├─ ...
+│ │ ├─ example.ts
│ │ ├─ ...
│ │ ├─ zora.ts
│ ├─ index.ts
```

#### 3. Define your chain

Define your chain data in `defineChain`.

Example:

```ts
// src/chains/definitions/example.ts
import { defineChain } from '../../utils/chain.js'

export const mainnet = /*#__PURE__*/ defineChain({
id: 1,
network: 'example',
name: 'Example Chain',
nativeCurrency: { name: 'Example', symbol: 'ETH', decimals: 18 },
rpcUrls: {
default: {
http: ['https://example.com'],
},
public: {
http: ['https://example.com'],
},
},
blockExplorers: {
etherscan: {
name: 'Etherscan',
url: 'https://etherscan.io',
},
default: {
name: 'Etherscan',
url: 'https://etherscan.io',
},
},
contracts: {
multicall3: {
address: '0xca11bde05977b3631167028862be2a173976ca11',
blockCreated: 69420,
},
},
})
```

#### 4. Export your chain

Export the chain in [`src/chains/index.ts`](../src/chains/index.ts).

Example:

```diff
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'
```

#### 4. Add changeset

Add a `patch` changeset with the description `"Added <your chain here> chain."`.

```diff
> pnpm changeset

What kind of change is this for viem?
+ patch

Please enter a summary for this change
+ Added Example chain.
```

#### 5. Open your PR

Now you are ready to open your Pull Request.

---

<div align="right">
<a href="#advanced-guide">&uarr; back to top</a></b>
</div>
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# viem

## 1.9.0

### Minor Changes

- [`e14eeb3b`](https://github.com/wagmi-dev/viem/commit/e14eeb3bd287a45e0c4fbed81847f7477b3e80e6) Thanks [@jxom](https://github.com/jxom)! - Migrated `@wagmi/chains` into viem and removed the `@wagmi/chains` dependency.

## 1.8.1

### Patch Changes
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "viem",
"description": "TypeScript Interface for Ethereum",
"version": "1.8.1",
"version": "1.9.0",
"scripts": {
"bench": "vitest bench",
"bench:ci": "CI=true vitest bench",
Expand Down Expand Up @@ -144,7 +144,6 @@
"@scure/bip32": "1.3.0",
"@scure/bip39": "1.2.0",
"@types/ws": "8.5.4",
"@wagmi/chains": "1.7.0",
"abitype": "0.9.8",
"isomorphic-ws": "5.0.0",
"ws": "8.12.0"
Expand Down Expand Up @@ -186,18 +185,18 @@
{
"name": "viem (cjs)",
"path": "./dist/cjs/index.js",
"limit": "60 kB"
"limit": "73 kB"
},
{
"name": "viem",
"path": "./dist/esm/index.js",
"limit": "50 kB",
"limit": "63 kB",
"import": "*"
},
{
"name": "viem/chains",
"path": "./dist/esm/chains/index.js",
"limit": "11 kB",
"limit": "16 kB",
"import": "*"
},
{
Expand All @@ -215,13 +214,13 @@
{
"name": "viem/chains (tree-shaking check)",
"path": "./dist/esm/chains/index.js",
"limit": "900 B",
"limit": "500 B",
"import": "{ mainnet }"
},
{
"name": "viem/ens (tree-shaking check)",
"path": "./dist/esm/ens.js",
"limit": "18 kB",
"limit": "19 kB",
"import": "{ getEnsAvatar }"
}
],
Expand Down
14 changes: 0 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions site/docs/clients/chains.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ head:

# Chains

The `viem/chains` entrypoint proxies the [`@wagmi/chains` NPM package](https://npm.im/@wagmi/chains), an official wagmi package which contains references to popular EVM-compatible chains such as: Polygon, Optimism, Avalanche, Base, Zora, and more.
The `viem/chains` entrypoint contains references to popular EVM-compatible chains such as: Polygon, Optimism, Avalanche, Base, Zora, and more.

## Usage

Expand All @@ -30,7 +30,9 @@ const client = createPublicClient({
})
```

[See here for a list of supported chains](https://github.com/wagmi-dev/references/tree/main/packages/chains/src).
[See here for a list of supported chains](https://github.com/wagmi-dev/viem/tree/main/src/chains/index.ts).

> Want to add a chain that's not listed in viem? Read the [Contributing Guide](https://github.com/wagmi-dev/viem/blob/main/.github/CONTRIBUTING.md#chains), and then open a Pull Request with your chain.
## Custom Chains

Expand Down
Loading

0 comments on commit 2492fbd

Please sign in to comment.