WalletChain
A chain as an app describes it to a wallet, for wallet_addEthereumChain (EIP-3085).
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
Section titled “Schemas”| Schema | Type | Describes | Used by |
|---|---|---|---|
WalletChain.schema |
WalletChain.WalletChain |
the chain to add | Wallet.addEthereumChain |
Fields
Section titled “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
Section titled “Behavior”- Only
chainIdis 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, anddecimalsstays a JSON number. - HTTPS URLs. By the EIP, a wallet rejects a URL with the
http:orfile:scheme. - Not for switching.
Wallet.switchEthereumChaintakes the chain id alone, in an object of its own.
Encode one with the schema to see what is sent.
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" }