{"eip":695,"title":"Create `eth_chainId` method for JSON-RPC","description":"Include ethchainId method in eth-namespaced JSON-RPC methods.","authors":["Isaac Ardis \u003cisaac.ardis@gmail.com\u003e","Wei Tang (@sorpaas)","Fan Torchz (@tcz001)","Erik Marks (@rekmarks)"],"status":"Final","type":"Standards Track","category":"Interface","created":"2017-08-21","requires":[155],"discussionsTo":"https://ethereum-magicians.org/t/eip-695-create-eth-chainid-method-for-json-rpc/1845","repo":"EIPs","label":"EIP-695","officialUrl":"https://eips.ethereum.org/EIPS/eip-695","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-695.md","url":"https://eips.huatuo.xyz/eip-695/","tldr":{"en":"Defines the eth_chainId JSON-RPC method, which returns the EIP-155 chain ID so wallets and dapps can reliably tell which chain a node serves before signing.","ja":"eth_chainId JSON-RPC メソッドを定義する。EIP-155 のチェーン ID を返すことで、ウォレットや dapp が署名前に、ノードがどのチェーンを扱っているかを確実に判別できる。","ko":"EIP-155 체인 ID를 반환하는 eth_chainId JSON-RPC 메서드를 정의해, 지갑과 dapp이 서명 전에 노드가 어떤 체인을 제공하는지 확실히 구분할 수 있게 한다.","zh":"定义 eth_chainId JSON-RPC 方法，返回 EIP-155 链 ID，使钱包和 dapp 在签名前能够可靠地判断节点服务的是哪条链。"},"tags":["json-rpc","chain-id","wallet","interface"],"explainers":{"en":{"lang":"en","tldr":"Defines the eth_chainId JSON-RPC method, which returns the EIP-155 chain ID so wallets and dapps can reliably tell which chain a node serves before signing.","tags":["json-rpc","chain-id","wallet","interface"],"related":[155,1474,3085,3326,1193],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-695/","markdown":"## What problem does it solve?\n\nSince [EIP-155](/eip-155/), every transaction signature includes a **chain ID** so it cannot be replayed on another chain. But there was no RPC call to ask a node which chain ID it uses. The closest option, `net_version`, returns the *network* ID, which is a separate value and does not always match.\n\nAn app could therefore connect to an Ethereum Classic node while thinking it was on Ethereum, or the other way around, and only find out when signing failed. The spec names wallet developers such as MetaMask as affected, since they needed this to support many chains.\n\n## How it works\n\n- **Method:** `eth_chainId`\n- **Params:** none\n- **Returns:** the chain ID as a hex `QUANTITY` string, for example `\"0x1\"` for Ethereum mainnet.\n\nThe value must match the rules at the node's **current head block**, so a caller can use it right away to sign a transaction on top of that head. If the head block has no chain ID, the node should act as if the method is unsupported and return an error.\n\nConsumers should use `eth_chainId` instead of `net_version` to identify a chain.\n\n## Sample code\n\nRaw JSON-RPC over HTTP:\n\n```sh\ncurl -s -X POST \"$RPC_URL\" \\\n  -H 'Content-Type: application/json' \\\n  --data '{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":1}'\n# {\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x1\"}\n```\n\nWith ethers v6 (it calls `eth_chainId` under the hood):\n\n```ts\nimport { JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst { chainId } = await provider.getNetwork();   // bigint\nif (chainId !== 1n) throw new Error(`wrong chain: ${chainId}`);\n\n// or directly\nconst hex: string = await provider.send(\"eth_chainId\", []);\nconsole.log(BigInt(hex)); // 1n\n```\n\nIn a browser wallet using the [EIP-1193](/eip-1193/) provider API:\n\n```ts\nconst chainIdHex = await window.ethereum.request({ method: \"eth_chainId\" });\n```\n\n## Things to know\n\n- The result is a hex string, not a number. Parse it before comparing (`BigInt(\"0x1\") === 1n`).\n- Chain ID and network ID are often equal, but not always. Always use the chain ID for signing.\n- The chain ID can change when a node follows a fork that changes it. Re-check on reconnect, and listen for the wallet's `chainChanged` event in dapps.\n- Wallet methods for adding or switching chains build on this: [EIP-3085](/eip-3085/) (`wallet_addEthereumChain`) and [EIP-3326](/eip-3326/) (`wallet_switchEthereumChain`).\n"},"ja":{"lang":"ja","tldr":"eth_chainId JSON-RPC メソッドを定義する。EIP-155 のチェーン ID を返すことで、ウォレットや dapp が署名前に、ノードがどのチェーンを扱っているかを確実に判別できる。","tags":["json-rpc","chain-id","wallet","interface"],"related":[155,1474,3085,3326,1193],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-695/","markdown":"## 何を解決するのか\n\n[EIP-155](/eip-155/) 以降、すべてのトランザクション署名には**チェーン ID** が含まれ、別のチェーンでリプレイされないようになっています。しかし、ノードがどのチェーン ID を使っているかを尋ねる RPC 呼び出しはありませんでした。最も近い `net_version` が返すのは*ネットワーク* ID で、これは別の値であり、常に一致するとは限りません。\n\nそのため、アプリは Ethereum に接続しているつもりで Ethereum Classic のノードに接続してしまう（あるいはその逆）ことがあり、署名が失敗して初めて気づくことになります。仕様書は、多くのチェーンに対応するためにこれを必要としていた MetaMask などのウォレット開発者を、影響を受ける側として挙げています。\n\n## 仕組み\n\n- **メソッド:** `eth_chainId`\n- **パラメーター:** なし\n- **戻り値:** 16 進の `QUANTITY` 文字列で表したチェーン ID。たとえば Ethereum メインネットなら `\"0x1\"`。\n\nこの値は、ノードの**現在のヘッドブロック**でのルールと一致している必要があります。これにより、呼び出し側はそのヘッドの上に積むトランザクションの署名にすぐ使えます。ヘッドブロックにチェーン ID がない場合、ノードはこのメソッドが未サポートであるかのように振る舞い、エラーを返すべきです。\n\nチェーンを識別するには、`net_version` ではなく `eth_chainId` を使ってください。\n\n## サンプルコード\n\nHTTP 上の生の JSON-RPC:\n\n```sh\ncurl -s -X POST \"$RPC_URL\" \\\n  -H 'Content-Type: application/json' \\\n  --data '{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":1}'\n# {\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x1\"}\n```\n\nethers v6 の場合（内部で `eth_chainId` を呼び出します）:\n\n```ts\nimport { JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst { chainId } = await provider.getNetwork();   // bigint\nif (chainId !== 1n) throw new Error(`wrong chain: ${chainId}`);\n\n// or directly\nconst hex: string = await provider.send(\"eth_chainId\", []);\nconsole.log(BigInt(hex)); // 1n\n```\n\n[EIP-1193](/eip-1193/) のプロバイダー API を使うブラウザウォレットの場合:\n\n```ts\nconst chainIdHex = await window.ethereum.request({ method: \"eth_chainId\" });\n```\n\n## 知っておくべきこと\n\n- 結果は数値ではなく 16 進文字列です。比較する前にパースしてください（`BigInt(\"0x1\") === 1n`）。\n- チェーン ID とネットワーク ID は等しいことが多いものの、常にそうとは限りません。署名には必ずチェーン ID を使ってください。\n- ノードがチェーン ID を変更するフォークに追従した場合、チェーン ID は変わることがあります。再接続時に再確認し、dapp ではウォレットの `chainChanged` イベントを監視してください。\n- チェーンの追加や切り替えのためのウォレットメソッドは、これを土台にしています。[EIP-3085](/eip-3085/)（`wallet_addEthereumChain`）と [EIP-3326](/eip-3326/)（`wallet_switchEthereumChain`）です。\n"},"ko":{"lang":"ko","tldr":"EIP-155 체인 ID를 반환하는 eth_chainId JSON-RPC 메서드를 정의해, 지갑과 dapp이 서명 전에 노드가 어떤 체인을 제공하는지 확실히 구분할 수 있게 한다.","tags":["json-rpc","chain-id","wallet","interface"],"related":[155,1474,3085,3326,1193],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-695/","markdown":"## 어떤 문제를 해결하나요?\n\n[EIP-155](/eip-155/) 이후 모든 트랜잭션 서명에는 **체인 ID**가 들어가, 다른 체인에서 재사용(리플레이)될 수 없습니다. 그런데 노드가 어떤 체인 ID를 쓰는지 묻는 RPC 호출은 없었습니다. 가장 가까운 `net_version`이 반환하는 것은 *네트워크* ID로, 이는 별개의 값이며 항상 일치하지는 않습니다.\n\n그래서 앱은 이더리움에 연결했다고 생각하면서 실제로는 이더리움 클래식 노드에 연결할 수 있었고(반대도 마찬가지), 서명이 실패한 뒤에야 알게 됩니다. 명세는 여러 체인을 지원하려면 이 기능이 필요했던 MetaMask 같은 지갑 개발자들을 영향을 받는 쪽으로 꼽습니다.\n\n## 어떻게 동작하나요?\n\n- **메서드:** `eth_chainId`\n- **매개변수:** 없음\n- **반환값:** 16진수 `QUANTITY` 문자열로 된 체인 ID. 예를 들어 이더리움 메인넷은 `\"0x1\"`입니다.\n\n이 값은 노드의 **현재 헤드 블록**에서 적용되는 규칙과 일치해야 하므로, 호출자는 그 헤드 위에 쌓일 트랜잭션에 서명할 때 바로 사용할 수 있습니다. 헤드 블록에 체인 ID가 없으면 노드는 이 메서드를 지원하지 않는 것처럼 동작하며 오류를 반환해야 합니다.\n\n체인을 식별할 때는 `net_version` 대신 `eth_chainId`를 사용해야 합니다.\n\n## 샘플 코드\n\nHTTP로 보내는 원시 JSON-RPC:\n\n```sh\ncurl -s -X POST \"$RPC_URL\" \\\n  -H 'Content-Type: application/json' \\\n  --data '{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":1}'\n# {\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x1\"}\n```\n\nethers v6 사용 시(내부적으로 `eth_chainId`를 호출합니다):\n\n```ts\nimport { JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst { chainId } = await provider.getNetwork();   // bigint\nif (chainId !== 1n) throw new Error(`wrong chain: ${chainId}`);\n\n// or directly\nconst hex: string = await provider.send(\"eth_chainId\", []);\nconsole.log(BigInt(hex)); // 1n\n```\n\n[EIP-1193](/eip-1193/) provider API를 쓰는 브라우저 지갑에서:\n\n```ts\nconst chainIdHex = await window.ethereum.request({ method: \"eth_chainId\" });\n```\n\n## 알아둘 점\n\n- 결과는 숫자가 아니라 16진수 문자열입니다. 비교하기 전에 파싱하세요(`BigInt(\"0x1\") === 1n`).\n- 체인 ID와 네트워크 ID는 같은 경우가 많지만 항상 그런 것은 아닙니다. 서명에는 항상 체인 ID를 사용하세요.\n- 노드가 체인 ID를 바꾸는 포크를 따라가면 체인 ID가 달라질 수 있습니다. 재연결할 때 다시 확인하고, dapp에서는 지갑의 `chainChanged` 이벤트를 수신하세요.\n- 체인을 추가하거나 전환하는 지갑 메서드는 이를 기반으로 합니다. [EIP-3085](/eip-3085/)(`wallet_addEthereumChain`)와 [EIP-3326](/eip-3326/)(`wallet_switchEthereumChain`)입니다.\n"},"zh":{"lang":"zh","tldr":"定义 eth_chainId JSON-RPC 方法，返回 EIP-155 链 ID，使钱包和 dapp 在签名前能够可靠地判断节点服务的是哪条链。","tags":["json-rpc","chain-id","wallet","interface"],"related":[155,1474,3085,3326,1193],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-695/","markdown":"## 它解决什么问题？\n\n自 [EIP-155](/eip-155/) 起，每笔交易的签名都包含**链 ID**，使其无法在另一条链上被重放。但当时没有任何 RPC 调用可以询问节点使用的是哪个链 ID。最接近的 `net_version` 返回的是*网络* ID，这是另一个值，并不总是与链 ID 一致。\n\n因此，应用可能以为自己连的是以太坊，实际却连上了以太坊经典（Ethereum Classic）的节点，反之亦然，直到签名失败才会发现。规范点名 MetaMask 等钱包开发者受到影响，因为他们要支持多条链，需要这个功能。\n\n## 它如何运作\n\n- **方法：** `eth_chainId`\n- **参数：** 无\n- **返回：** 以十六进制 `QUANTITY` 字符串表示的链 ID，例如以太坊主网为 `\"0x1\"`。\n\n该值必须与节点**当前头区块**适用的规则一致，这样调用者可以立即用它为建立在该头区块之上的交易签名。如果头区块没有链 ID，节点应表现得如同不支持该方法，并返回错误。\n\n使用方应使用 `eth_chainId` 而不是 `net_version` 来识别一条链。\n\n## 示例代码\n\n通过 HTTP 发送的原始 JSON-RPC：\n\n```sh\ncurl -s -X POST \"$RPC_URL\" \\\n  -H 'Content-Type: application/json' \\\n  --data '{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":1}'\n# {\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x1\"}\n```\n\n使用 ethers v6（底层会调用 `eth_chainId`）：\n\n```ts\nimport { JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst { chainId } = await provider.getNetwork();   // bigint\nif (chainId !== 1n) throw new Error(`wrong chain: ${chainId}`);\n\n// or directly\nconst hex: string = await provider.send(\"eth_chainId\", []);\nconsole.log(BigInt(hex)); // 1n\n```\n\n在使用 [EIP-1193](/eip-1193/) provider API 的浏览器钱包中：\n\n```ts\nconst chainIdHex = await window.ethereum.request({ method: \"eth_chainId\" });\n```\n\n## 需要注意\n\n- 结果是十六进制字符串，而不是数字。比较之前请先解析（`BigInt(\"0x1\") === 1n`）。\n- 链 ID 和网络 ID 经常相等，但并非总是如此。签名时务必使用链 ID。\n- 当节点跟随一个会更改链 ID 的分叉时，链 ID 可能发生变化。重新连接时请重新检查，在 dapp 中则要监听钱包的 `chainChanged` 事件。\n- 添加或切换链的钱包方法都建立在它之上：[EIP-3085](/eip-3085/)（`wallet_addEthereumChain`）和 [EIP-3326](/eip-3326/)（`wallet_switchEthereumChain`）。\n"}},"requiredBy":[1193,3326]}
