Setup your own private Ethereum Private Network (Part 1)

This tutorial series will help you to quickly to spin up a private ethereum blockchain. We will be setup our private ethereum network on Google cloud. You can use use do it with any cloud provider like aws or azure. At the end of this series you will be able to setup your own private ethereum network and can access it using metamask.

This series is divided into 3parts:

  1. create genesis file.
  2. setup ethereum nodes in GCP
  3. connecting the node to metamask

Genesis file

A genesis block is the first block of a blockchain. Modern versions of Bitcoin assign it block number 0, though older versions gave it number 1. The genesis block is almost always hardcoded into the software. It is a special case in that it does not reference a previous block, and for Bitcoin and almost all of its derivatives, it produces an unspendable subsidy.

Genesis files are the starting point of launching a private/custom chain and are used to define and configure a the new blockchain. The genesis file defines parameters of your private chain. If you wanted to change the block time, gas limit, or other variables- this is the place to do it and hence start working on a ‘custom’ Ethereum blockchain.

To run a private network you need to provide geth with some basic information required to create the initial block.

{
"config": {
"chainId": 0,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x20000",
"extraData" : "",
"gasLimit" : "0x2fefd8",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}

Explanation of genesis file

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 (PoF).

The combination of nonce and mixhash must satisfy a mathematical condition. It allows to verify that the Block has really been cryptographically mined, thus, from this aspect, is valid.

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.

The final nonce value is the result of the the mining process iteration, in which the algorithm was able to discover a nonce value that satisfies the Mining Target. The Mining Target is a cryptographically described condition that strongly depends on the applied . Just by using the nonce Proof-of-Work, the validity of a Block can verified very quickly.

difficulty

It defines the Mining Target, which can be calculated from the previous block’s difficulty level and the timestamp. The higher the difficulty, the statistically more calculations a Miner must perform to discover a valid block. This value is used to control the Block generation time of a Blockchain, keeping the Block generation frequency within a target range. On the test network, we 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.

alloc

Allows to define a list of pre-filled wallets. That’s a Ethereum specific functionality to handle the “Ether pre-sale” period. Since we can mine local Ether quickly, we don’t use this option.

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.

gaslimit

Gas limit refers to the maximum amount of gas you’re willing to spend on a particular transaction. A higher gas limits mean that more computational work must be done to execute the smart contract. A standard ETH transfer requires a gas limit of 21,000 units of gas.

chainid

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.

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.

This article helped you? Long press on the 👏 button as long as you can. That motivates me to write more articles for you.

I got something wrong? Mention it in the comments. I would love to improve.

Hello World, I am Aditya. A creative developer and a logical designer. You can find me on Linkedin or stalk me on GitHub ? If that’s too social for you, just drop a mail to adityaprakashjoshi1@gmail.com if you wish to talk tech with me.

Have a nice day!

I am a Blockchain Engineer, having a good experience in nodejs, Android, and latest technologies. I am Certified Hyperledger Fabric Administrator (CHFA)