EIPs

EIP-3326 — wallet_switchEthereumChain

eips.ethereum.org/EIPS/eip-3326

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

ExportTypePurpose
wallet_switch_ethereum_chainSignable<null>Request the switch.
SwitchEthereumChainParameter, SwitchEthereumChainParameterstypes
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