Genesis Block - cogeorg/teaching GitHub Wiki
Every blockchain starts with the genesis block. In case you want to start your own private network, this genesis block needs to be defined. Here's an example of a custom genesis.json
file
{
"config": {
"chainId": 1234,
"homesteadBlock": 1,
"eip150Block": 2,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 3,
"eip158Block": 3,
"byzantiumBlock": 4,
"ethash": {}
},
"nonce": "0x0",
"timestamp": "0x5b0e9dce",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b760",
"difficulty": "0x80000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"0000000000000000000000000000000000000000": {
"balance": "0x1"
}, ...
}
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
config The config part contains the network ID, here called chainId, and the block numbers for various hard fork rules that have been added to the Ethereum chain over time.
nonce The nonce is the cryptographically secure mining proof-of-work that proves beyond reasonable doubt that a particular amount of computation has been expended in the determination of this token value (Yellowpaper, 11.5. Mining Proof-of-Work). It is a natural number that needs to be set such that the hash of the block complies with the defined difficulty.
timestamp A scalar value equal to the reasonable output of Unix time() function at this block inception. This mechanism enforces a homeostasis in terms of the time between blocks. A smaller period between the last two blocks results in an increase in the difficulty level and thus additional computation required to find the next valid block. If the period is too large, the difficulty, and expected time to the next block, is reduced. The timestamp also allows verifying the order of block within the chain (Yellowpaper, 4.4.4).
extraData An optional free, but max. 32-byte long space to conserve smart things for ethernity. :)
gasLimit A scalar value equal to the current chain-wide limit of gas expenditure per block. On a private network, it is recommended that you make this high to avoid being limited by this threshold during tests. Note: this does not indicate that we should not pay attention to the gas consumption of our contracts.
difficulty A scalar value corresponding to the difficulty level applied during the nonce discovering of this block. It defines the mining target, which can be calculated from the previous block’s difficulty level and the timestamp. The higher the difficulty, statistically the more calculations a miner must perform to discover a valid block. This value is used to control the blocks' generation time of a blockchain, keeping the block generation frequency within a target range. On a private network, keep this value low to avoid waiting during tests, since the discovery of a valid block is required to execute a transaction on the blockchain.
mixhash A 256-bit hash which proves, combined with the nonce, that a sufficient amount of computation has been carried out on this block: the Proof-of-Work (PoW). The combination of nonce and mixhash must satisfy a mathematical condition described in the Ethereum Yellowpaper, 4.4.4. Block Header Validity. It allows to verify that the block has really been cryptographically mined, thus is valid.
coinbase The 160-bit address to which all rewards (in Ether) collected from the successful mining of this block are transferred. They are a sum of the mining reward itself and the contract transaction execution refunds. Often named “beneficiary” in the specifications, sometimes “etherbase” in the online documentation. This can be set to an arbitrary value in the genesis block since each miner specifies her address whenever she creates a new block.
alloc Allows defining a list of pre-filled wallets. That’s an Ethereum specific functionality to handle the “Ether pre-sale” period. Since Ether can be quickly mined locally, there's no need to explicitly use this option.
parentHash The Keccak 256-bit hash of the entire parent block header (including its nonce and mixhash). It is the pointer to the parent block, thus effectively building the chain of blocks. In the case of the genesis block, and only in this case, it’s 0.