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
2019-06-20 12:02:58 +02:00
author: Isaac Ardis < isaac.ardis @gmail .com > , Wei Tang (@sorpaas ), Fan Torchz (@tcz001 )
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
2019-06-20 13:03:59 +02:00
status: Last Call
review-period-end: 2019-07-20
2018-03-21 12:51:05 +00:00
created: 2017-08-21
2019-06-20 13:03:59 +02:00
requires: 155, 1474
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-05-06 01:15:26 -07:00
introduced via [EIP-155 ](https://eips.ethereum.org/EIPS/eip-155 ).
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-05-06 01:15:26 -07:00
signing as introduced by [EIP-155 ](https://eips.ethereum.org/EIPS/eip-155 ).
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
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
// 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
## 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
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.
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/ ).