Here it's described in Ethereum's go implementation.
type ChainConfig struct {
ChainId *big.Int `json:"chainId"` // Chain id identifies the current chain and is used for replay protection
A few questions:
- How is it different than
networkID
? - Is
chainID
andnetworkID
needed in every block or just the genesis block? - Can you give a specific example of what it means when it says
chainID
is used "for replay protection"?
EDIT: Still unanswered:
What would happen in the situation that you set networkID
to one of the mainnet networkID
s, but change the other config variables to whatever you want? Why does it matter what you set for networkID if you're running a local chain?
Best Answer
ChainID was introduced in EIP-155 to prevent replay attacks between the main ETH and ETC chains, which both have a networkID of
1
.It's basically just an additional way to tell chains apart. Subsequent to EIP-155, ETH has a chainID of
1
, while ETC has a chainID of61
(even though they still have the same networkID of1
).It's required for the chain to operate in general - e.g. it's required when signing transactions, meaning transactions signed on the ETH network end up with a different hash than those signed on ETC. Before EIP-155, signed transactions on each network would look the same, and could be replayed.
Edit:
A specific example of how chainId is used.
As per the EIP-155 page, the
v
value of a transaction's signature is dependent on the value of chainID.There is a detailed example of how this is applied on the EIP-155 page.