Geth Parameters – Networkid vs. Genesis Block ChainId Configuration

genesisgo-ethereumnetworkid

I have set up a private Ethereum network with a custom chainId (for example 67890) specified in the config part of the genesis.json file, did geth init genesis.json, and got the private net up and running. However then I noticed some weird things like the web3 sendTransaction doesn't work as it says invalid sender, only after I specify the chainId explicitly in the transaction json to 67890 then it can send out the transaction correctly.

So I tried some test and found out that when I run web3.eth.net.getNetworkType() it returns privatenet, but when I run web3.eth.net.getId() it returns 1. And after some fumbling, I found out that I need to add a –networkid 67890 in the geth commandline parameter for the web3.eth.net.getId() to return the correct value of 67890.

So my question is, what's the difference between specifying the networkid in geth commandline and specifying the chainId in genesis.json? I thought the networkid and chainId are one and the same, and it seems that web3 uses the value of the networkid for the default value of the transaction chainId, but somehow when I start geth without explicit networkid parameter, it will ignore the chainId config and still use 1 as default, resulting in a different networkid from the chainId.

So for an ethereum blockchain, does it really make sense for the networkid and chainId to be different from each other, or is it some kind of bug?

Best Answer

  1. Network id and Chain id are the same thing

  2. You can edit NetworkId in eth/config.go & params/config.go and get rid of this problem forever, you won't need to specify network id on the commandline anymore.

  3. Ethereum's geth has hardcoded the value 1 in the files I told you , so this is why you have these problems.

  4. The chain id is now part of transaction as result of Ethereum Improvement Proposal (EIP) #155, so the invalid sender is shown because chain id is different. You can disable this using EIP155BlockNum , but you would be vulnerable to replay attack, if you use multiple networks, like a testnet for example.

  5. chain id is not part of the block's hash, so specifying it in the genesis file is really useless. What you have to do instead, is specify chainID in the source code or using commandline parameters.