Developers worldwide are experimenting with the 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 an exact blockchain setup only for yourself, you have to define a couple of things. One of them is genesis.json, a file where you determine all specifications about your blockchain’s genesis block.

What is a genesis block?

The 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 set up 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 your 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 the genesis block, which you can find in Ethereum documentation.

{
    “config”: {
        “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 a 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 the 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 the 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 that 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 difficulty level aims 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 a 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 a 160-bit hash and the number of ETH with which an account should be funded. It should look like something this

“alloc”: {
    “2sa2a321h8353vba12as8965r3340huk3s6a2h6e”: { “balance”: “10″ },
    “1sc2a371h8c53vba12as89c5r3340huk3s6a2h6e”: { “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 covering Ethereum private blockchain setup. Soon we plan to publish more articles on this topic, so sign up below to be updated and get exclusive content from our knowledge lab!