Learn about Ethereum blockchain development
If you are new to the blockchain technology, taking our Introduction to Blockchain Technology self-paced course is highly recommended. Also, for a comprehensive coverage of blockchain development in Ethereum or mastering Solidity programming, taking our below self paced courses is highly recommended:
In our previous article (Review of Private and Permissioned blockchain), we discussed the differences between private and permissioned blockchain networks.
In this article, we learn how to set up a local private Ethereum network.
In addition to the enterprise needs of a private blockchain, there are other reasons for setting up a local private Ethereum blockchain.
As we discussed before smart contracts are immutable and can be very costly once deployed to the Ethereum mainnet. It is always recommended to follow the best practices in coding, security, and economics, and have the code thoroughly tested before it is deployed on the Ethereum network. With a local private blockchain, it makes it easy and convenient for the developers to test smart contracts and simulate the contract's behaviors. You can even deploy smart contracts to the single instance of a local Ethereum blockchain without running a full node.
In this article, we will show you how to create multiple local nodes and configure and establish the private blockchain, as well as set up mining on the private chain.
In the context of trust model for permissioned blockchain, everyone in a permissioned network is properly identified and not pseudonymous. Therefore, proof of work mining, which will limit 51% takeover, is not required. Unless and until permissioned blockchain gets large enough and it looks like a permissionless network, mining will be necessary again.
By creating the genesis block, we will create our private blockchain. The following steps are all you will need to run a non-mining private Ethereum blockchain:
We are going to run the Ethereum client Geth to create a private blockchain with only one user: ourselves. Let's get started:
1. First, open up a Terminal window and navigate to any directory that you want. From there, we are going to create the hello_world directory to host the data of the two blocks, as follows:
$ mkdir hello_world
2. We will also create a subdirectory under hello_world to host all the logs. First, navigate to the directory we just created, that is, hello_world. Next, a directory named logs , as follows:
$ cd hello_world $ mkdir logs
With the directories created, we have set up the environment to configure the genesis file. Let's move on to the next step.
A genesis block is the starting point of every blockchain. We can configure a genesis block through customizing a genesis.json file. There are a few components to be configured within the file, including a config struct for initializing the blockchain, and alloc to allocate the initial funds. In addition to that, there are a few other configuration parameters for mining and gas limits.
The following is the config structure definition in Geth:
The genesis.json file of a private blockchain can be configured as follows:
"homesteadBlock":0, "eip155Block":0, "eip158Block":0
Let's take a look at the preceding code:
In order to keep our blockchain private, we need to customize the genesis block in the genesis.json configuration file:
In the hello_world directory, let's save the genesis.json sample to a file named the same as genesis.json. You can create the file and write it using the editor of your choice. If you happen to use vim, the command is as follows:
$ vi genesis.json
Right now, we have saved the starting point of a private chain to the environment that we set up. We will use this genesis block to create a database in the next article.
In our next article (How to Run Geth on a Local Private Ethereum Blockchain), we discuss how to setup and run Geth on a local private Ethereum network.
This article is written in collaboration with Brian Wu who is a leading author of “Learn Ethereum: Build your own decentralized applications with Ethereum and smart contracts” book. He has written 7 books on blockchain development.
Here is the list of our free webinars that are highly recommended:
Here is the list of our 10 free self-paced courses that are highly recommended:
If you like to learn more about Hyperledger Fabric, Hyperledger Sawtooth, Ethereum or Corda, taking the following self-paced classes is highly recommended:
If you want to master Hyperledger Fabric, Ethereum or Corda, taking the following live classes is highly recommended:
If you like to learn more about blockchain technology and how it works, reading the following articles is highly recommended:
If you like to learn more about blockchain development in Ethereum with Solidity, reading the following articles and tutorials is highly recommended:
If you like to learn more about blockchain development with Hyperledger, reading the following articles and tutorials is highly recommended:
If you like to learn more about blockchain development on Corda , reading the following articles and tutorials is highly recommended:
If you like to learn more about blockchain development in other platforms, reading the following articles and tutorials is highly recommended:
We offer private custom tutoring classes both online and in DC, MD and VA for almost all of our courses or bootcamps. Give us a call or email us to discuss your needs.
$50 Limited OfferREGISTER NOW