Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement 'eth_chainId' JSON-RPC method #336

Merged
merged 1 commit into from Aug 18, 2017

Conversation

@whilei
Copy link
Contributor

commented Aug 16, 2017

Rel #335

I chose to return the number in hexadecimal format because that's consistent with the other eth_ call returning a *big.Int eth_gasPrice. I'm not set on this; it may be better to return as a plain int since there's no need for _big_ness. Another option would be to return as a string, akin to net_version, which returns "1" and "2".

In case no chain id is configured, it will return 0.

Finally, it may be useful to also include the fork number at which EIP155 is implemented for the given configuration; Morden -> 1915000, Mainnet -> 3000000, custom/private -> n

Eg:
Current proposed:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x3d"
}

or possibly with fork number:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
      "chainId": "0x3d",
      "blockNumber": "0x2dc6c0"
    }
}

Thoughts welcome.

problem: implement eth_chainId json RPC method
solution: do it

- update changelog

fixes #335

@whilei whilei force-pushed the whilei:id-schm-id branch from 30170f6 to ddaff64 Aug 16, 2017

@whilei whilei requested a review from sorpaas Aug 17, 2017

@sorpaas
Copy link
Contributor

left a comment

I think what currently proposed would be good. Not every client would be able to return the fork block number. For example, in Parity chainID is hardcoded.

I would also suggest we try to get chainID RPC into Parity and ETH's go-ethereum. This would help a lot in helping apps such as MetaMask to support multi-chain.

sorpaas added a commit to sorpaas/parity that referenced this pull request Aug 18, 2017
Add RPC eth_chainId for querying the current blockchain chain ID
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. 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.

The same RPC endpoint is also about to be merged for ETC's
go-ethereum: ethereumproject/go-ethereum#336

@whilei whilei merged commit 9728a51 into ethereumproject:master Aug 18, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
gavofyork added a commit to paritytech/parity-ethereum that referenced this pull request Sep 26, 2017
Add RPC eth_chainId for querying the current blockchain chain ID (#6329)
* Add RPC eth_chainId for querying the current blockchain chain ID

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. 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.

The same RPC endpoint is also about to be merged for ETC's
go-ethereum: ethereumproject/go-ethereum#336

* Add eth_chainId to js's web3 interface

* Add a mocked test for eth_chainId

* Add chainId in js's jsonrpc interfaces

* Change return type for eth_chainId to `Option<u64>`

* Change name eth_chainId to parity_chainId

* Wrong test name and missed var for rpc_parity_chain_id test

* Use U256 to return chainId and fix for master

u64 returns decimal integer, and there seems to be no type called
U64. So here I use U256 to return the hex integer.

* Fix chainID test

Before EIP155 fork number, chainID should be null.

* Change both parity_chainId and transaction::chainId to use U64

This makes it consistent that all chain ids returned are hex string.

* Fix wrong U64 serialization
@axic axic referenced this pull request Jan 26, 2018
@hackmod hackmod referenced this pull request Sep 10, 2018
0 of 2 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.