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

eth,internal: add eth_chainId method to PublicEthereumApi JSONRPC #15002

Closed
wants to merge 2 commits into from

Conversation

whilei
Copy link

@whilei whilei commented Aug 18, 2017

I'm stealing @sorpaas words from his congruent Parity client PR:

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.

Recently merged the same endpoint to ETC's go-ethereum: ethereumproject/go-ethereum#336

@GitCop
Copy link

GitCop commented Aug 18, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: dc0641c96ee4368b8df740a869a76310b26a8682
  • Commits must be prefixed with the package(s) they modify

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

@whilei whilei changed the title Add eth_chainId method to PublicEthereumApi JSONRPC eth,internal: add eth_chainId method to PublicEthereumApi JSONRPC Aug 18, 2017
@karalabe
Copy link
Member

Would be nice to have an EIP for it before adding methods to the standardized eth_ namespace.

@tcz001
Copy link

tcz001 commented Aug 21, 2017

Good to see this, I was facing with same problem when using Web3js, which was using the net_getId by default, just created a EIP694

@whilei
Copy link
Author

whilei commented Aug 21, 2017

Please find an EIP PR here: ethereum/EIPs#695

@bas-vk
Copy link
Member

bas-vk commented Sep 4, 2017

The proper way to retrieve the chainID is:

if config := api.e.chainConfig; config.IsEIP155(api.e.blockchain.CurrentBlock().Number()) {
		chainID = config.ChainId
}

Although the EIP is not finalized it is likely that a QUANTITY is returned. You can return one the of integer types in the hexutil package for that. They will take care of the appropiate encoding that is used for quantity types.

holiman
holiman previously approved these changes Sep 27, 2017
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parity just added this method aswell, looks good to me.
Actually, hold that. How will this respond when doing e.g. a full-sync, before reaching EIP-155?

@whilei
Copy link
Author

whilei commented Sep 27, 2017

It will return hexutil.Uint(new(big.Int)) == 0x0, which does not conflict with any existing chainId in EIP155.

@frankiebee
Copy link

whats the status on this? seems like a stale PR. did chainId make it in somewhere else?

@turbobit
Copy link

turbobit commented Jun 5, 2018

ESN ( https://ethersocial.org ) using customized RPC-API for using Metamask.
api : https://api-meta.esn.gonspool.com
api return RPC call "net_version" as chainId value "31102"
"chainId 31102 " is ESN's chainid.

by using this customized RPC-API.
i am sucess send a coin with

@fjl
Copy link
Contributor

fjl commented Sep 29, 2018

Closing in favor of #17617

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants