Learn BlockChain Development with me #3: genesis.json explained and start genesis block with Geth

in utopian-io •  7 years ago  (edited)

In this post, I am going to share about what genesis.json file is and how you start a private network with Geth. Geth is a Go-Implementation of the Ethereum Protocol.

What Will I Learn?

  • What is genesis.json
  • How to start your private network with Geth

Requirements

  • Geth Installed (if you have not installed Geth, read my previous post)
  • basic understanding of blockchain and genesis block
  • Preferred UNIX based platform (Linux/Mac)

Difficulty

Intermediate

Tutorial Contents

genesis.json

genesis.json is a JSON file that stores how the genesis block looks like, to initialize your own private blockchain.

The name genesis.json is by convention.

{
  "config": {
    "chainId": 33,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "nonce": "0x0000000000000033",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x8000000",
  "difficulty": "0x100",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {}
}

genesis.json

Source

  • config - Configuration to describe the chain.
  • nonce - Need to be used to initialize the blockchain.
  • timestamp - State when was the block generated.
  • parentHash - Hash of the entire parent block header.
  • gasLimit - Ether require gas to make transaction. However, there is an upper limit for the gas payment. The higher the limit, the more complicated smart contract can be done.
  • difficulty - Defines how difficult to mine a new block.
  • mixhash - combined with nonce.
  • coinbase - Your address.
  • alloc - Preallocated Ether accounts

To read more about details of each of the parameters, check out this stackexchange answer.

Create a Genesis Block

The directory currently look like this:

/
|- genesis.json

Run geth --datadir=./chaindata/ init ./genesis.json to generate the chaindata which will set genesis block for your chain.

Screen Shot 2018-01-31 at 11.38.25 AM.png

It will generate a chaindata file. From there, run geth --datadir=./chaindata/ to start the geth

Screen Shot 2018-01-31 at 11.39.48 AM.png

Then the private network has started.

Now, look for the ipc (for mac/linux) location.

INFO [01-31|11:39:40] IPC endpoint opened: /Volumes/HDD/files/blockchain/ethereum/chaindata/geth.ipc

You have successfully created a genesis block! In the next tutorial, I will share about getting started with EthereumTestRPC NPM library.

Curriculum

  1. #1: Introduction to Blockchain and Smart Contract
  2. #2: Ethereum Node and Install Development tools



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Hey @superoo7 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

hey so nice I really like your post! Lets make steemit together to a better place with our content! I would like to read a bit more about you? Look my Introduceyourself like I do it. I went to jail because of cryptos : https://steemit.com/bitcoin/@mykarma/3-jail-review-from-colombia-to-madrid-and-then-straight-to-jailng-time

Does every cryptocurrency, e.g. Bitcoin, Etherium has only one genesis block or multiple genesis block?

Genesis block also known as the first block , so normally it is the only one.
And not all cryptocurrency using blockchain, for my tutorial is mainly deal with ethereum.

Thanks.
I am learning crypto and blockchain, I have read up some info online, and also your 1# and 2# posting. Your postings are too technical for me at the moment. But it is good for me to expose to such technical staff.

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

join me and lets build the fastest blockchain!!

I guess you are way too hyped! I am still learning using smart contract on top of ethereum, still far away from
that LOL 😂