Configure the Genesis Block
Configure the genesis block of a private blockchain network with Geth.
The genesis block is the first block in the blockchain and serves as the foundation of the network. Therefore, our blockchain also needs a genesis block. The Ethereum Mainnet genesis block can't be used because our blockchain is private and has a different consensus algorithm as well as different settings and features.
The genesis block of a private Ethereum network created using Geth can be configured using a JSON file (genesis.json
). This file defines several parameters for the initial block, including the Ethereum protocol version, the initial difficulty level, the timestamp, and the account balances of the initial nodes on the network. It also specifies any custom rules or configurations that the network should use, e.g., the gas limit and the consensus algorithm.
The genesis.json
file
The genesis.json
file is the configuration file used to initialize the genesis block of a Geth private blockchain. The file path must be provided to the Geth node on start-up so that the genesis block can be created, with the following parameters provided :
config
: To configure the features enabled at launch time.gasLimit
: The gas limit for blocks (this impacts how much EVM computation can happen within a single block).alloc
: To allocate Ethers to some addresses.extradata
: To include relevant data for the network.
The config
section
The config
section contains the following parameters:
chainId
: Represents the identification number of our blockchain network (the ID must be chosen to ensure that is not already being used by another existing network).homesteadBlock, eip150Block, eip155Block, eip158Block, byzantiumBlock, constantinopleBlock, petersburgBlock, istanbulBlock, berlinBlock
: Each parameter represents the evolution of the protocol rules. A value different from zero indicates the block number at which the network will transition to new protocol rules.Consensus algorithm: The possible values for a private Geth network can be
clique
orethash
. The first is a PoA consensus mechanism, while the latter is PoW.
As we’re going to use the Clique PoA consensus. It should be configured with the following two parameters:
period
: This parameter defines the duration of each block period in seconds. A block period of 15 seconds means that a new block is added to the blockchain every 15 seconds on average, as long as valid transactions are waiting to be included in a block.epoch
: In the Clique consensus algorithm, validators are selected based on their membership in a predefined list or Clique, which is periodically updated. Theepoch
parameter specifies the number of blocks that must be added to the chain before the Clique is updated.
A possible configuration for the Clique consensus algorithm could be:
Get hands-on with 1400+ tech skills courses.