Developers all over the world are experimenting with Ethereum blockchain and many of them find Ethereum testnet hard to use. Because of that, you may want to set up your private blockchain network. You would have full control over that network, and would not have any blockchain apps that you don’t need. So if you want to have a clear blockchain setup only for yourself, there are a couple of things you have to define. One of them is genesis.json, a file in which you determine all specifications about genesis block of your blockchain.

So, what exactly is genesis block? Genesis block is the first block of a blockchain. Since it’s the first block, it does not reference a previous block and has to be hardcoded into the configurations.

It’s not so hard to setup everything, but it’s a little bit harder to understand what you are doing. Been there, done that. In this article we will try to explain params that you have to define for you genesis block. That way we can help the community to use a blockchain with more understanding, which will result in better apps and development community.

How does the genesis file look like?

Here is an example of genesis block which you can find in Ethereum documentation.

            "chainId": 0, 
            "homesteadBlock": 0, 
            "eip155Block": 0, 
            "eip158Block": 0 
 "nonce": "0x0000000000000042”, 
 "timestamp": "0x0”, 
 "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000”, 
 "extraData": "0x0”, 
 "gasLimit": "0x8000000”, 
 "difficulty": "0x400”, 
 "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000”, 
 "coinbase": "0x3333333333333333333333333333333333333333”, 
 "alloc": { } 

Params explained

We will explain all those params, one by one. Let’s start with an exciting part.

config – It’s not a required param and we can remove it from genesis.json, but we added it in this example to let you know that it exists. If you are creating your private blockchain, you don’t need the last three params so just set them to 0. The first param chainId is a unique identificator of the chain so you can set it to any number, or just leave it as 0.

nonce –  It’s a 64-bit string hash, this string is used in combination with mixhash. Since Ethereum uses proof of work, it’s used to prove that a sufficient amount of computation has been carried out on this block. Both of them combined must satisfy the mathematical condition described in the Yellowpaper, in the paragraph describing Block Header Validity. According to that paper, the mining proof of work exists as a cryptographically secure nonce which proves, beyond reasonable doubt, that a particular amount of computation has been expended in the determination of some token value n.

timestamp – According to the Ethereum paper, the timestamp is a scalar value equal to the reasonable output of Unix’s time() at this block’s inception. It’s used for the mechanism that enforces homeostasis in terms of time between blocks. If the time difference between two blocks is small, the difficulty level increases.. If that happens, additional computation will be required to find the next valid block. Otherwise, the difficulty will decrease if the time difference between two blocks is too big. Timestamp param is used to modify difficulty if needed.

parentHash – The Keccak 256-bit hash of the parent block’s header. That is kinda a pointer to the parent block needed to form a real chain of blocks. For those familiar with programming, it’s similar to the linked list mechanism. A genesis block has no parent block so the result will, only in this case, be equal to 0.

extraData – An arbitrary byte array containing data relevant to this block. Also, it’s an optional param which can’t be bigger than 32 bytes.

gasLimit – It’s a scalar value equal to the current limit of gas expenditure per block. Transactions also have gasLimit param, and we have to be aware that a sum of gasLimits of all transactions in the block must not be greater than the block’s gasLimit.

difficulty – This param is a scalar value corresponding to the difficulty level of a particular block. For blocks this can be calculated from the previous block’s difficulty level and a timestamp, but in this case we don’t have previous blocks  so the difficulty has to be defined. The purpose of the difficulty level is to control the block generation time of a blockchain, to keep block generation frequency within range. If the difficulty is high, miners have to perform more calculations, while lower value means that miners have to perform fewer calculations to validate a block.

mixHash – A 256-bit hash which, combined with the nonce, proves that a sufficient amount of computation has been carried out on the block.

coinbase – it’s a 160-bit ethereum address where all rewards collected from the successful block validation will be transferred. A reward is a sum of the mining reward and the refunds from executing contract transactions. Since it’s a genesis block, the value for this block can be anything. For all the next blocks the value will be an address set by the miner who validated that block.

alloc – this param is used to pre-fund some eth addresses. It contains two parameters, the address that has to be 160-bit hash and the number of ETH with which an account should be funded. It should look like something this

"alloc": { 
                "balance": “10" 
                "balance": “25" 

If you would like to know more about Ethereum block parameters, please read their paper and Ethereum stack exchange which will provide you more info on how those params collaborate with each other.

This is just the first article that covers Ethereum private blockchain setup, soon we plan to publish more articles on this topic.