Beginners guide to Ethereum (3) — explain the genesis file and use it to customize your blockchain

Image for post
Image for post

Overview

This tutorial serves as a complete guide that combines all the information you will need about a genesis file, including some of the ethereum history background for your better understanding:)

Important Notes before you start

Please be aware that the settings of the genesis file presented below may be outdated in the future if changes(hard forks) are made by the Ethereum Foundation. The tutorial below is to help developers have a better understanding through starting evrything from scratch. But you can always do this in a much more easier way: Use the official CLI that is automatically installed followed withgethcalled puppeth, which helps create and customize your genesis file. Simply type puppeth in your terminal window and you will be prompted to input the required parameters such as where should the file be saved at, which consensus to use(PoW or PoA), and which accounts should be prefunded. Here is a sample usage tutorial.

What is a genesis file

The genesis block is the start of the blockchain, and the genesis.json is the file that defines it. It is like the “settings” for your blockchain. For example, the chain configuration, level of difficulty to mine blocks, etc.

{"config": {"chainId": 15, "homesteadBlock": 0,"eip155Block": 0,"eip158Block": 0},"difficulty": "20","gasLimit": "2100000","alloc": {"7df9a875a174b3bc565e6424a0050ebc1b2d1d82": 
{ "balance": "300000" },
"f41c74c9ae680c1aa78f42e5647a62f353b7bdde":
{ "balance": "400000" }
}}
  • “homesteadBlock”: Homestead is the second major release of Ethereum(the first release is Frontier). The value 0 means that you are using this release.
  • “epi155Block”: epi stands for Ethereum Improvement Proposal, where developers propose ideas on how to improve Ethereum and contribute to this project.

Start coding!

Hint: you can create a new folder and use it for testing

cat > genesis.json
geth init genesis.json --datadir test
geth --helpgeth init --help // the two output is different
geth --networkid 123 --datadir test console 
// remember the datadir has to be the same
eth.getBalance("7df9a875a174b3bc565e6424a0050ebc1b2d1d82")
miner.setEtherbase("7df9a875a174b3bc565e6424a0050ebc1b2d1d82")
// you can also use arbitrary address as long as there are 40 digits
miner.start()

Wrap up

After the three tutorial, you should have more experience with geth, have a taste of how blockchain is set up and how it can start mining. Hope you like it. I’m open to any suggestion. Thank you:)

Taipei Ethereum Meetup

台北以太坊社群專欄

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store