The genesis object
The chain spec states that the Ethereum blockchain must be generated from a single block, called the genesis block. This is a special one, because it doesn't have information from previous blocks, and it contains the configuration of the entire blockchain.
It's based on a genesis.json file, and it has the following parameters:
- name: This is the chain name. For instance, Homestead, Constantinople, and Morden.
- forkName: This is an optional secondary name for this chain.
- engine: This is an enum that specifies the consensus engine, which can be Ethash or Null.
- params: This is an object with several attributes of the consensus engine if you specified Ethash only. The different parameters are as follows:
- minimumDifficulty: This is a number specifying the minimum difficulty a block may have.
- gasLimitBoundDivisor: This is a separator string. It is usually 0x400 which is the character @ when converted to an utf8 string.
- difficultyBoundDivisor: This is an integer specifying the difficulty per block, which must be divisible by two. For instance, 2084.
- durationLimit: This is the point at which difficulty is increased.
- blockReward: This is the reward for discovering an Ethereum block.
- registrar: This is the Ethereum address of the registrar contract on this chain.
Different consensus engines may allow different keys in the params object, however there are a few common to all:
- accountStartNonce: This integer specifies what nonce all newly created accounts should have.
- frontierCompatibilityModeLimit: This integer specifies the number of the block that frontier-compatibility mode finishes, and homestead mode begins.
- maximumExtraDataSize: This integer specifies the maximum size in bytes of the extra_data field of the header.
- minGasLimit: This integer specifies the minimum amount of gas a block may be limited at.
- networkID: This integer specifies the index of this chain on the network.
- genesis: An object with the header of the genesis block as you saw in Chapter 1, Blockchain Architecture. The header contains specific information about the contents of the block, such as the gas used, the timestamp, and the nonce.
The genesis object contains a series of mandatory parameters for the first block created, namely the following:
- seal
- difficulty
- author
- timestamp
- parentHash
- extraData
- gasLimit
- nodes: An array of strings containing the initial nodes of the blockchain in the enode format. We'll later see how it's structured.
- accounts: An object with the accounts of the genesis block. Each account must have several keys about each address:
- balance: How much Ether this account has specified in wei.
- nonce: The nonce of the account at genesis, which will usually be zero.
- code: The address of the contract associated with this account or any other.
- storage: The object mapping hex-encoded integers for the account's storage at genesis.
- builtin: An alternative to code used to specify that the account's code is natively implemented. Value is an object with further fields:
- name: The name of the built-in code to execute as a string such as identity or ecrecover.
- pricing: An enum to specify the cost of calling this contract.
- linear: This specifies a linear cost to calling this contract. Value is an object with two fields: base, which is the basic cost in Wei and is always paid; and word, which is the cost per word of input, rounded up.
Now that you know which parameters go into the genesis.json file, you can start creating your own private blockchain with custom parameters for your own personal applications. In Chapter 3, Ethereum Assets, you'll learn the exact process for creating a custom Ethereum blockchain.
Now, you possess the fundamental understanding about how Ethereum blockchains are kick-started, how they operate, and a solid perception about how to create your own personalized blockchain for testing purposes.