# WalletChain

A chain as an app describes it to a wallet, for `wallet_addEthereumChain` (EIP-3085).

```ts
import { Wallet, type WalletChain } from "@ethect/core/rpc";

const base: WalletChain.WalletChain = {
  chainId: 8453,
  chainName: "Base",
  nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
  rpcUrls: ["https://mainnet.base.org"],
  blockExplorerUrls: ["https://basescan.org"],
};

const add = Wallet.addEthereumChain(base);
```

## Schemas

| Schema | Type | Describes | Used by |
| --- | --- | --- | --- |
| `WalletChain.schema` | `WalletChain.WalletChain` | the chain to add | [`Wallet.addEthereumChain`](https://ethect.dev/rpc/wallet/add-ethereum-chain/) |

## Fields

| Field | Type | Notes |
| --- | --- | --- |
| `chainId` | `number` | sent as a hex quantity |
| `chainName` | `string` (optional) | the name the wallet shows |
| `nativeCurrency` | `{ name: string, symbol: string, decimals: number }` (optional) | the currency that pays for gas |
| `rpcUrls` | `ReadonlyArray<string>` (optional) | the endpoints the wallet reaches the chain through |
| `blockExplorerUrls` | `ReadonlyArray<string>` (optional) | |
| `iconUrls` | `ReadonlyArray<string>` (optional) | |

## Behavior

- **Only `chainId` is required.** The EIP asks for nothing more, but a wallet that does not
  know the chain rejects it without a name, a currency and RPC URLs.
- **The chain id is a `number`.** It is encoded as a hex quantity, and `decimals` stays a JSON
  number.
- **HTTPS URLs.** By the EIP, a wallet rejects a URL with the `http:` or `file:` scheme.
- **Not for switching.** [`Wallet.switchEthereumChain`](https://ethect.dev/rpc/wallet/switch-ethereum-chain/)
  takes the chain id alone, in an object of its own.

Encode one with the schema to see what is sent.

```ts
import { Schema } from "effect";
import { WalletChain } from "@ethect/core/rpc";

const wire = Schema.encodeEffect(WalletChain.schema)({
  chainId: 8453,
  chainName: "Base",
});
// succeeds with { chainId: "0x2105", chainName: "Base" }
```
