web3j icon indicating copy to clipboard operation
web3j copied to clipboard

Add support for determining network version automatically

Open conor10 opened this issue 6 years ago • 5 comments

The net_version JSON-RPC call provides information on the network the Ethereum client is connected to.

This information could be cached in web3j's RawTransactionManager, following the first transaction call, enabling web3j to automatically support EIP155 in full.

conor10 avatar Sep 18 '17 10:09 conor10

Do I understand it correctly that after this change this code in the RawTransactionManager:

    if (chainId > ChainId.NONE) {
        ...
    }

will be replaced with something like:

    if (getChainId() > ChainId.NONE) {
        ...
    }

where getChainId() is:

    private byte getChainId() {
        // Return cached chainId or return a call "net_version"
    }

mushketyk avatar Mar 20 '18 07:03 mushketyk

Chain id != net version ...

fcorneli avatar Apr 02 '18 10:04 fcorneli

The only way to get the correct chain id, is to get the latest block and analyze the signature on the (first) transaction. If EIP-155 is not enabled on your private network, then chain id can be null, and thus different from the network version.

fcorneli avatar Apr 21 '18 10:04 fcorneli

There is a JSON RPC endpoint eth_chainId, https://github.com/ethereum/EIPs/blob/master/EIPS/eip-695.md

It's implemented by the major clients Geth, Classic, Parity, Besu, Quorum and in Ganache...

Happy to submit a PR

magooster avatar Nov 03 '19 05:11 magooster

Hi All, is this issue closed and changes made?

soumyajitsamanta avatar Mar 20 '22 13:03 soumyajitsamanta