EIPs
EIP-3326 — wallet_switchEthereumChain
Switches the wallet’s active chain.
import { wallet_switch_ethereum_chain } from "@ethernauta/eip/3326";
await wallet_switch_ethereum_chain({
chain_id: "0x2105", // Base
})(signer({ chain_id: eip155_1.chain_id })); Surface
| Export | Type | Purpose |
|---|---|---|
wallet_switch_ethereum_chain | Signable<null> | Request the switch. |
SwitchEthereumChainParameter, SwitchEthereumChainParameters | types | |
| schemas |
Error handling
If the chain isn’t recognized, the wallet returns error code 4902 (unrecognized_chain). The canonical pattern:
try {
await wallet_switch_ethereum_chain({ chain_id })(signer({ chain_id: current }));
} catch (err) {
if (err.code === 4902) {
await wallet_add_ethereum_chain(chain_definition)(signer({ chain_id: current }));
await wallet_switch_ethereum_chain({ chain_id })(signer({ chain_id: current }));
} else {
throw err;
}
} Wallet behavior
The wallet may either auto-accept (chain previously authorized) or prompt the user. Auto-accept is the default for chains the user has used before; the Ethernauta wallet’s select-chain view shows up only on first switch to a given chain.
The chainChanged event (EIP-1193) fires after the switch settles.
See also
- EIP-3085 — add a chain first if unknown.
- EIP-1193 —
chainChangedevent. - Wallet → select-chain view.