{"eip":3326,"title":"Wallet Switch Ethereum Chain RPC Method (`wallet_switchEthereumChain`)","description":"An RPC method for switching the wallet's active Ethereum chain.","authors":["Erik Marks (@rekmarks)"],"status":"Stagnant","type":"Standards Track","category":"Interface","created":"2021-03-04","requires":[155,695],"discussionsTo":"https://ethereum-magicians.org/t/eip-3326-wallet-switchethereumchain","repo":"EIPs","label":"EIP-3326","officialUrl":"https://eips.ethereum.org/EIPS/eip-3326","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3326.md","url":"https://eips.huatuo.xyz/eip-3326/","tldr":{"en":"Defines wallet_switchEthereumChain, the RPC call a dApp uses to ask the user's wallet to switch its active chain by chain ID.","ja":"wallet_switchEthereumChain を定義する。dApp がユーザーのウォレットに、チェーン ID を指定してアクティブなチェーンの切り替えを依頼するための RPC 呼び出し。","ko":"wallet_switchEthereumChain을 정의한다. dApp이 사용자의 지갑에 체인 ID로 활성 체인을 전환해 달라고 요청하는 RPC 호출이다.","zh":"定义 wallet_switchEthereumChain，dApp 用这个 RPC 调用请求用户的钱包按链 ID 切换其当前活动链。"},"tags":["wallet","json-rpc","chain-id","multichain","interface"],"explainers":{"en":{"lang":"en","tldr":"Defines wallet_switchEthereumChain, the RPC call a dApp uses to ask the user's wallet to switch its active chain by chain ID.","tags":["wallet","json-rpc","chain-id","multichain","interface"],"related":[3085,695,1193,155,1102],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-3326/","markdown":"## What problem does it solve?\n\nMany wallets work with one chain at a time, the **active chain**, and forward all RPC requests to it. A dApp built for a specific network (an L2, a testnet) previously had to tell the user \"please switch your wallet to network X\" and wait for them to do it by hand.\n\nEIP-3326 gives dApps a standard request to ask the wallet to switch for them. The wallet still decides, usually by showing the user a confirmation.\n\n## How it works\n\nMethod: `wallet_switchEthereumChain`\n\n- **Params**: one object, `{ chainId: string }`. The chain ID is a hex string, as returned by `eth_chainId` ([EIP-695](/eip-695/)), e.g. `\"0x1\"` for mainnet.\n- **Returns**: `null` if the wallet switched; an error otherwise.\n\nThe wallet **must** reject the request if:\n\n- the `chainId` is malformed,\n- the wallet does not know the chain or cannot serve RPC requests for it,\n- the wallet has no concept of a single active chain.\n\nThe wallet **may** refuse for any other reason, such as the user declining.\n\nThe method deliberately carries no RPC URLs or chain metadata. Adding a chain the wallet does not know yet is the job of `wallet_addEthereumChain` ([EIP-3085](/eip-3085/)).\n\n## Sample code\n\nSwitch, and fall back to adding the chain if the wallet does not know it:\n\n```ts\nconst ethereum = (window as any).ethereum;\n\nasync function ensureChain(chainIdHex: string, addParams?: object) {\n  try {\n    await ethereum.request({\n      method: \"wallet_switchEthereumChain\",\n      params: [{ chainId: chainIdHex }],\n    });\n  } catch (err: any) {\n    // MetaMask uses error code 4902 for \"unrecognized chain\"; other wallets may differ.\n    if (err?.code === 4902 \u0026\u0026 addParams) {\n      await ethereum.request({ method: \"wallet_addEthereumChain\", params: [addParams] });\n    } else {\n      throw err; // e.g. 4001: user rejected\n    }\n  }\n}\n\nawait ensureChain(\"0x1\"); // Ethereum mainnet\n```\n\nRaw JSON-RPC form:\n\n```json\n{ \"id\": 1, \"jsonrpc\": \"2.0\", \"method\": \"wallet_switchEthereumChain\", \"params\": [{ \"chainId\": \"0x1\" }] }\n```\n\n## Things to know\n\n- Status is **Stagnant**, but the method is widely implemented by browser wallets and is the de facto way dApps request a network switch.\n- Error codes for \"unknown chain\" are not defined by this EIP; handle errors defensively.\n- After a switch, listen for the `chainChanged` event ([EIP-1193](/eip-1193/)) and re-read state; do not assume the switch succeeded just because you asked.\n- **Security**: a silent switch could trick users into signing on the wrong chain. The spec says wallets should show a confirmation naming the requester and target chain, and should cancel pending requests and confirmations for the old chain.\n- **Privacy**: auto-rejecting unknown chains can let a site probe which chains a wallet supports.\n- Wallets that serve several chains at once may not have an \"active chain\" at all; newer multichain wallet APIs move away from this model.\n"},"ja":{"lang":"ja","tldr":"wallet_switchEthereumChain を定義する。dApp がユーザーのウォレットに、チェーン ID を指定してアクティブなチェーンの切り替えを依頼するための RPC 呼び出し。","tags":["wallet","json-rpc","chain-id","multichain","interface"],"related":[3085,695,1193,155,1102],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-3326/","markdown":"## 何を解決するのか\n\n多くのウォレットは、一度に 1 つのチェーン、つまり**アクティブなチェーン**で動作し、すべての RPC リクエストをそこに転送します。特定のネットワーク（L2 やテストネット）向けに作られた dApp は、以前は、ユーザーに「ウォレットをネットワーク X に切り替えてください」と伝え、手動で切り替えてくれるのを待たなければなりませんでした。\n\nEIP-3326 は、dApp がウォレットに切り替えを依頼するための標準的なリクエストを提供します。最終的に決めるのはウォレットで、通常はユーザーに確認を表示します。\n\n## 仕組み\n\nメソッド: `wallet_switchEthereumChain`\n\n- **パラメーター**: オブジェクト 1 つ、`{ chainId: string }`。チェーン ID は、`eth_chainId`（[EIP-695](/eip-695/)）が返すものと同じ 16 進文字列です。たとえばメインネットなら `\"0x1\"` です。\n- **戻り値**: ウォレットが切り替えた場合は `null`、そうでなければエラー。\n\nウォレットは、次の場合にリクエストを拒否し**なければなりません**。\n\n- `chainId` の形式が不正な場合、\n- ウォレットがそのチェーンを知らない、またはそのチェーンの RPC リクエストを処理できない場合、\n- ウォレットに単一のアクティブなチェーンという概念がない場合。\n\nウォレットは、ユーザーが拒否した場合など、それ以外の理由でも拒否してもよい（**may**）とされています。\n\nこのメソッドには、RPC URL やチェーンのメタデータが意図的に含まれていません。ウォレットがまだ知らないチェーンを追加するのは、`wallet_addEthereumChain`（[EIP-3085](/eip-3085/)）の役目です。\n\n## サンプルコード\n\n切り替えを試み、ウォレットがそのチェーンを知らない場合は、チェーンの追加にフォールバックする:\n\n```ts\nconst ethereum = (window as any).ethereum;\n\nasync function ensureChain(chainIdHex: string, addParams?: object) {\n  try {\n    await ethereum.request({\n      method: \"wallet_switchEthereumChain\",\n      params: [{ chainId: chainIdHex }],\n    });\n  } catch (err: any) {\n    // MetaMask uses error code 4902 for \"unrecognized chain\"; other wallets may differ.\n    if (err?.code === 4902 \u0026\u0026 addParams) {\n      await ethereum.request({ method: \"wallet_addEthereumChain\", params: [addParams] });\n    } else {\n      throw err; // e.g. 4001: user rejected\n    }\n  }\n}\n\nawait ensureChain(\"0x1\"); // Ethereum mainnet\n```\n\n生の JSON-RPC の形:\n\n```json\n{ \"id\": 1, \"jsonrpc\": \"2.0\", \"method\": \"wallet_switchEthereumChain\", \"params\": [{ \"chainId\": \"0x1\" }] }\n```\n\n## 知っておくべきこと\n\n- ステータスは **Stagnant** ですが、このメソッドはブラウザウォレットに広く実装されており、dApp がネットワークの切り替えを依頼する事実上の標準的な方法です。\n- 「未知のチェーン」に対するエラーコードは、この EIP では定義されていません。エラーは慎重に処理してください。\n- 切り替え後は、`chainChanged` イベント（[EIP-1193](/eip-1193/)）を待ち受け、状態を読み直してください。依頼したからといって、切り替えが成功したと思い込まないでください。\n- **セキュリティ**: 黙って切り替えられると、ユーザーが誤ったチェーンで署名してしまうおそれがあります。仕様は、ウォレットが依頼元と切り替え先のチェーンを明示した確認を表示し、旧チェーンに対する保留中のリクエストと確認をキャンセルするべきだとしています。\n- **プライバシー**: 未知のチェーンを自動的に拒否すると、サイトがそのウォレットのサポートするチェーンを探れてしまう場合があります。\n- 複数のチェーンを同時に扱うウォレットには、そもそも「アクティブなチェーン」がないことがあります。新しいマルチチェーン向けのウォレット API は、このモデルから離れつつあります。\n"},"ko":{"lang":"ko","tldr":"wallet_switchEthereumChain을 정의한다. dApp이 사용자의 지갑에 체인 ID로 활성 체인을 전환해 달라고 요청하는 RPC 호출이다.","tags":["wallet","json-rpc","chain-id","multichain","interface"],"related":[3085,695,1193,155,1102],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-3326/","markdown":"## 어떤 문제를 해결하나요?\n\n많은 지갑은 한 번에 하나의 체인, 즉 **활성 체인**으로 동작하며 모든 RPC 요청을 그곳으로 전달합니다. 특정 네트워크(L2, 테스트넷)용으로 만든 dApp은 예전에는 사용자에게 \"지갑을 네트워크 X로 바꿔 주세요\"라고 안내한 뒤 사용자가 직접 바꾸기를 기다려야 했습니다.\n\nEIP-3326은 dApp이 지갑에 대신 전환해 달라고 요청하는 표준 요청을 제공합니다. 최종 결정은 여전히 지갑이 하며, 보통 사용자에게 확인을 표시합니다.\n\n## 어떻게 동작하나요?\n\n메서드: `wallet_switchEthereumChain`\n\n- **파라미터**: 객체 하나, `{ chainId: string }`. 체인 ID는 `eth_chainId`([EIP-695](/eip-695/))가 반환하는 것과 같은 16진수 문자열입니다. 예를 들어 메인넷은 `\"0x1\"`입니다.\n- **반환**: 지갑이 전환했으면 `null`, 아니면 오류.\n\n지갑은 다음의 경우 요청을 거부**해야 합니다**.\n\n- `chainId`의 형식이 잘못된 경우,\n- 지갑이 해당 체인을 모르거나 그 체인에 대한 RPC 요청을 처리할 수 없는 경우,\n- 지갑에 단일 활성 체인이라는 개념이 없는 경우.\n\n지갑은 사용자가 거부하는 경우 등 그 밖의 어떤 이유로든 거부**할 수 있습니다**.\n\n이 메서드는 RPC URL이나 체인 메타데이터를 의도적으로 담지 않습니다. 지갑이 아직 모르는 체인을 추가하는 일은 `wallet_addEthereumChain`([EIP-3085](/eip-3085/))의 몫입니다.\n\n## 샘플 코드\n\n전환하고, 지갑이 체인을 모르면 체인 추가로 폴백하기:\n\n```ts\nconst ethereum = (window as any).ethereum;\n\nasync function ensureChain(chainIdHex: string, addParams?: object) {\n  try {\n    await ethereum.request({\n      method: \"wallet_switchEthereumChain\",\n      params: [{ chainId: chainIdHex }],\n    });\n  } catch (err: any) {\n    // MetaMask uses error code 4902 for \"unrecognized chain\"; other wallets may differ.\n    if (err?.code === 4902 \u0026\u0026 addParams) {\n      await ethereum.request({ method: \"wallet_addEthereumChain\", params: [addParams] });\n    } else {\n      throw err; // e.g. 4001: user rejected\n    }\n  }\n}\n\nawait ensureChain(\"0x1\"); // Ethereum mainnet\n```\n\n원시 JSON-RPC 형태:\n\n```json\n{ \"id\": 1, \"jsonrpc\": \"2.0\", \"method\": \"wallet_switchEthereumChain\", \"params\": [{ \"chainId\": \"0x1\" }] }\n```\n\n## 알아둘 점\n\n- 상태는 **Stagnant**이지만, 이 메서드는 브라우저 지갑에 널리 구현되어 있으며 dApp이 네트워크 전환을 요청하는 사실상의 표준 방식입니다.\n- \"알 수 없는 체인\"에 대한 오류 코드는 이 EIP가 정의하지 않습니다. 오류를 방어적으로 처리하세요.\n- 전환 후에는 `chainChanged` 이벤트([EIP-1193](/eip-1193/))를 수신하고 상태를 다시 읽으세요. 요청했다는 이유만으로 전환이 성공했다고 가정하지 마세요.\n- **보안**: 조용한 전환은 사용자가 엉뚱한 체인에서 서명하도록 속일 수 있습니다. 명세는 지갑이 요청자와 대상 체인을 명시한 확인을 표시하고, 이전 체인에 대한 보류 중인 요청과 확인을 취소해야 한다고 말합니다.\n- **프라이버시**: 알 수 없는 체인을 자동으로 거부하면 사이트가 지갑이 지원하는 체인을 탐색할 수 있게 될 수 있습니다.\n- 여러 체인을 동시에 제공하는 지갑에는 \"활성 체인\"이 아예 없을 수 있습니다. 최신 멀티체인 지갑 API는 이 모델에서 벗어나고 있습니다.\n"},"zh":{"lang":"zh","tldr":"定义 wallet_switchEthereumChain，dApp 用这个 RPC 调用请求用户的钱包按链 ID 切换其当前活动链。","tags":["wallet","json-rpc","chain-id","multichain","interface"],"related":[3085,695,1193,155,1102],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-3326/","markdown":"## 它解决什么问题？\n\n许多钱包一次只处理一条链，即**活动链**，并把所有 RPC 请求转发给它。针对特定网络（某个 L2、某个测试网）构建的 dApp，以前只能告诉用户\"请把你的钱包切换到网络 X\"，然后等用户手动完成。\n\nEIP-3326 为 dApp 提供了一个标准请求，请钱包代为切换。最终仍由钱包决定，通常会向用户显示确认。\n\n## 它如何运作\n\n方法：`wallet_switchEthereumChain`\n\n- **参数**：一个对象，`{ chainId: string }`。链 ID 是十六进制字符串，与 `eth_chainId`（[EIP-695](/eip-695/)）返回的一致，例如主网为 `\"0x1\"`。\n- **返回**：如果钱包已切换则返回 `null`；否则返回错误。\n\n在以下情况下，钱包**必须**拒绝该请求：\n\n- `chainId` 格式不正确，\n- 钱包不认识该链，或无法为其处理 RPC 请求，\n- 钱包没有单一活动链的概念。\n\n钱包**可以**出于任何其他原因拒绝，例如用户拒绝。\n\n该方法有意不携带 RPC URL 或链元数据。添加钱包尚不认识的链，是 `wallet_addEthereumChain`（[EIP-3085](/eip-3085/)）的职责。\n\n## 示例代码\n\n切换，如果钱包不认识该链，则回退为添加该链：\n\n```ts\nconst ethereum = (window as any).ethereum;\n\nasync function ensureChain(chainIdHex: string, addParams?: object) {\n  try {\n    await ethereum.request({\n      method: \"wallet_switchEthereumChain\",\n      params: [{ chainId: chainIdHex }],\n    });\n  } catch (err: any) {\n    // MetaMask uses error code 4902 for \"unrecognized chain\"; other wallets may differ.\n    if (err?.code === 4902 \u0026\u0026 addParams) {\n      await ethereum.request({ method: \"wallet_addEthereumChain\", params: [addParams] });\n    } else {\n      throw err; // e.g. 4001: user rejected\n    }\n  }\n}\n\nawait ensureChain(\"0x1\"); // Ethereum mainnet\n```\n\n原始 JSON-RPC 形式：\n\n```json\n{ \"id\": 1, \"jsonrpc\": \"2.0\", \"method\": \"wallet_switchEthereumChain\", \"params\": [{ \"chainId\": \"0x1\" }] }\n```\n\n## 需要注意\n\n- 状态为 **Stagnant**，但该方法已被浏览器钱包广泛实现，是 dApp 请求切换网络的事实标准方式。\n- 本 EIP 没有定义\"未知链\"的错误码；请谨慎地处理错误。\n- 切换之后，请监听 `chainChanged` 事件（[EIP-1193](/eip-1193/)）并重新读取状态；不要仅因为你发出了请求，就认为切换已经成功。\n- **安全**：静默切换可能诱使用户在错误的链上签名。规范指出，钱包应显示一个注明请求方和目标链的确认，并应取消针对旧链的待处理请求和确认。\n- **隐私**：自动拒绝未知链，可能让网站借此探测钱包支持哪些链。\n- 同时服务多条链的钱包可能根本没有\"活动链\"；较新的多链钱包 API 正在偏离这种模型。\n"}}}
