2018-03-20 15:10:58 +00:00
---
2018-03-21 12:51:05 +00:00
eip: 695
title: Create `eth_chainId` method for JSON-RPC
2020-05-14 01:18:27 -07:00
author: Isaac Ardis < isaac.ardis @gmail .com > , Wei Tang (@sorpaas ), Fan Torchz (@tcz001 ), Erik Marks (@rekmarks )
2019-06-20 12:02:58 +02:00
discussions-to: https://ethereum-magicians.org/t/eip-695-create-eth-chainid-method-for-json-rpc/1845
2018-03-21 15:55:18 +00:00
type: Standards Track
2018-03-21 12:51:05 +00:00
category: Interface
2020-05-26 21:32:24 +02:00
status: Final
2018-03-21 12:51:05 +00:00
created: 2017-08-21
2020-09-07 16:32:22 -07:00
requires: 155
2018-03-20 15:10:58 +00:00
---
2017-08-21 11:17:47 -05:00
## Simple Summary
2019-06-20 12:02:58 +02:00
2017-08-21 11:17:47 -05:00
Include `eth_chainId` method in `eth_` -namespaced JSON-RPC methods.
## Abstract
2019-06-20 12:02:58 +02:00
2017-08-21 11:17:47 -05:00
The `eth_chainId` method should return a single STRING result
for an integer value in hexadecimal format, describing the
2019-06-20 12:02:58 +02:00
currently configured `CHAIN_ID` value used for signing replay-protected transactions,
2020-09-30 12:22:43 +08:00
introduced by [EIP-155 ](./eip-155.md ).
2017-08-21 11:17:47 -05:00
## Motivation
2019-06-20 12:02:58 +02:00
Currently although we can use `net_version` RPC call to get the
2017-08-21 11:17:47 -05:00
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.
## Specification
2019-06-20 12:02:58 +02:00
### `eth_chainId`
2017-08-21 11:17:47 -05:00
2019-06-20 12:02:58 +02:00
Returns the currently configured chain ID, a value used in replay-protected transaction
2020-09-30 12:22:43 +08:00
signing as introduced by [EIP-155 ](./eip-155.md ).
2017-08-21 11:17:47 -05:00
2020-05-04 19:29:14 +02:00
The chain ID returned should always correspond to the information in the current known
head block. This ensures that caller of this RPC method can always use the retrieved
information to sign transactions built on top of the head.
2020-05-12 07:25:29 -07:00
If the current known head block does not specify a chain ID, the client should treat any
calls to `eth_chainId` as though the method were not supported, and return a suitable
error.
2019-06-20 12:02:58 +02:00
#### Parameters
None.
2017-08-21 11:17:47 -05:00
2019-06-20 12:02:58 +02:00
#### Returns
2017-08-21 11:17:47 -05:00
2019-06-20 12:02:58 +02:00
`QUANTITY` - integer of the current chain ID.
#### Example
2017-08-21 11:17:47 -05:00
```js
2020-12-03 14:09:20 +00:00
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":83}'
2017-08-21 11:17:47 -05:00
// Result
{
2019-06-22 15:48:54 -04:00
"id": 83,
2017-08-21 11:17:47 -05:00
"jsonrpc": "2.0",
"result": "0x3d" // 61
}
```
## Rationale
2019-06-20 12:02:58 +02:00
2017-08-21 11:17:47 -05:00
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.
## Backwards Compatibility
2019-06-20 12:02:58 +02:00
Not relevant.
2017-08-21 11:17:47 -05:00
2020-05-13 12:11:52 -07:00
## Security Considerations
Consumers should prefer `eth_chainId` over `net_version` , so that they can reliably identify chain they are communicating with.
2020-09-30 12:22:43 +08:00
Implementers should take care to implement `eth_chainId` correctly and promote its use, since the chain ID is critical in replay attack prevention as described in [EIP-155 ](./eip-155.md ), and consumers will rely on it to identify the chain they are communicating with.
2020-05-13 12:11:52 -07:00
2017-08-21 11:17:47 -05:00
## Implementation
2019-06-20 12:02:58 +02:00
- [Parity PR ](https://github.com/paritytech/parity/pull/6329 )
- [Geth PR ](https://github.com/ethereum/go-ethereum/pull/17617 )
- [Geth Classic PR ](https://github.com/ethereumproject/go-ethereum/pull/336 )
2017-08-21 11:17:47 -05:00
2018-01-26 19:28:59 +09:00
## Reference
2020-05-14 01:18:27 -07:00
Return value `QUANTITY` adheres to standard JSON RPC hex value encoding, as documented in the [Ethereum Wiki ](https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding ).
2018-01-26 19:28:59 +09:00
2017-08-21 11:17:47 -05:00
## Copyright
2019-06-20 12:02:58 +02:00
2017-08-21 11:17:47 -05:00
Copyright and related rights waived via [CC0 ](https://creativecommons.org/publicdomain/zero/1.0/ ).