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 10:02:58 +00: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 11:03:59 +00: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 11:03:59 +00:00
requires: 155, 1474
2018-03-20 15:10:58 +00:00
---
2017-08-21 16:17:47 +00:00
## Simple Summary
2019-06-20 10:02:58 +00:00
2017-08-21 16:17:47 +00:00
Include `eth_chainId` method in `eth_` -namespaced JSON-RPC methods.
## Abstract
2019-06-20 10:02:58 +00:00
2017-08-21 16:17:47 +00:00
The `eth_chainId` method should return a single STRING result
for an integer value in hexadecimal format, describing the
2019-06-20 10:02:58 +00:00
currently configured `CHAIN_ID` value used for signing replay-protected transactions,
2018-01-26 02:40:17 +00:00
introduced via [EIP-155 ](./eip-155.md ).
2017-08-21 16:17:47 +00:00
## Motivation
2019-06-20 10:02:58 +00:00
Currently although we can use `net_version` RPC call to get the
2017-08-21 16:17:47 +00: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 10:02:58 +00:00
### `eth_chainId`
2017-08-21 16:17:47 +00:00
2019-06-20 10:02:58 +00:00
Returns the currently configured chain ID, a value used in replay-protected transaction
2018-01-26 02:50:32 +00:00
signing as introduced by [EIP-155 ](./eip-155.md ).
2017-08-21 16:17:47 +00:00
2019-06-20 10:02:58 +00:00
#### Parameters
None.
2017-08-21 16:17:47 +00:00
2019-06-20 10:02:58 +00:00
#### Returns
2017-08-21 16:17:47 +00:00
2019-06-20 10:02:58 +00:00
`QUANTITY` - integer of the current chain ID.
#### Example
2017-08-21 16:17:47 +00:00
```js
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
// Result
{
2019-06-22 19:48:54 +00:00
"id": 83,
2017-08-21 16:17:47 +00:00
"jsonrpc": "2.0",
"result": "0x3d" // 61
}
```
## Rationale
2019-06-20 10:02:58 +00:00
2017-08-21 16:17:47 +00: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 10:02:58 +00:00
Not relevant.
2017-08-21 16:17:47 +00:00
## Implementation
2019-06-20 10:02:58 +00: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 16:17:47 +00:00
2018-01-26 10:28:59 +00: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 16:17:47 +00:00
## Copyright
2019-06-20 10:02:58 +00:00
2017-08-21 16:17:47 +00:00
Copyright and related rights waived via [CC0 ](https://creativecommons.org/publicdomain/zero/1.0/ ).