# 简要说明

Include eth_chainId method in eth_-namespaced JSON-RPC methods.

# 摘要

The eth_chainId method should return a single STRING result for an integer value in hexadecimal format, describing the currently configured CHAIN_ID value used for signing replay-protected transactions, introduced via EIP-155.

# 动机

Currently although we can use net_version RPC call to get the current network ID, there's no RPC for querying the chain ID. This makes it impossible to determine the current actual blockchain using the RPC.

# 规范

# eth_chainId

Returns the currently configured chain ID, a value used in replay-protected transaction signing as introduced by EIP-155.

# 参数

None.

# Returns

QUANTITY - integer of the current chain ID.

# 示例

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'

// Result
{
  "id": 83,
  "jsonrpc": "2.0",
  "result": "0x3d" // 61
}
1
2
3
4
5
6
7
8

# 原理阐述

An ETH/ETC client can accidentally connect to an ETC/ETH RPC endpoint without knowing it unless it tries to sign a transaction or it fetch a transaction that is known to have signed with a chain ID. This has since caused trouble for application developers, such as MetaMask, to add multi-chain support.

# 向后兼容

Not relevant.

# 实现

# Reference

Return value QUANTITY adheres to standard JSON RPC hex value encoding, as documented here: https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding.

# 版权

Copyright and related rights waived via CC0.