Very closely attributed to its name, the genesis block is the first or origin block of a private network on Ethereum. The genesis block contains all the essential information to configure the network as well as find related peers. It’s basically the config file for your Ethereum network. In fact to boot up your network, you actually need to pass in the location of the file as a param.
The genesis file is a simple JSON file that contains config thresholds. Here’s an example,
Though this file is by no means comprehensive, it does contain all the params that create a good base network.
config The file starts out with the “config” block which contains all the config parameters and thresholds that control the networks basic operations. Read more here.
- chainId: Protects the network from a replay attack. It acts like a offset to prevent attackers from deciphering continuous values in your network.
- homesteadBlock: Homestead is the second major release of Ethereum(the first release is Frontier). The value 0 means that you are using this release.
difficulty This determines how difficult it is to mine in your network. When developing on a test network, set it to the lowest possible value so you don’t have to wait too long for mining blocks.
gasLimit This defines the limit of gas cost per block. Set this value high to avoid being limited when testing.
nonce & mixhash Nonce and mixhash are values which when combines, allows to verify that a block has really been cryptographically mined, and thus is valid. The mixhash is 256-bit hash which proves, when combined with the 64-bit nonce, that a sufficient amount of computation has been carried out on this block: the Proof-of-Work (PoW).
alloc Allows defining a list of pre-filled wallets. That’s an Ethereum specific functionality to handle the “Ether pre-sale” period. You can also leave this as an empty hash.
There are many more parameters and configuration options you can add to the genesis block, but the ones mentioned above are the ones you’ll be absolutely needing.
Now that we have the genesis block, how do you start the network? Simple. Just run the following command (make sure you have geth installed!),
The above commands are for the Mac OS.
These commands do a few things:
- The first utilises the genesis file to seed the blockchain.
- It uses the datadir to store all state necessary to maintain the newly created blockchain.
- The second command opens up the console to that network.
- The IPC (interprocess communication) path is the local pipe between the node and UI and is only local to your host. It becomes important when attaching a console to a running node.
- Assign a port address to prevent the network from clashing with an already running process.
You’ve just started your own private Ethereum network!
This is a companion discussion topic for the original entry at https://www.skcript.com/svr/genesis-block-ethereum/