Note
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:
Recap
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.
Setting up a local private Ethereum blockchain
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.
Private blockchains without mining
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:
- Set up the environment.
- Configure the custom genesis file.
- Run Geth.
One-to-One Live Blockchain Classes
Coding Bootcamps school offers One-to-One Live Blockchain Classes for Beginners.
Setting up the environment
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.
Configuring the custom genesis file
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:
{ "config":{ "chainId":0205718128, "homesteadBlock":0, "eip155Block":0, "eip158Block":0 }, "alloc":{} }
Let’s take a look at the preceding code:
- config: This section holds the main blockchain configuration information. It has properties such as chainID, homesteadBlock, eip155Block, and eip158Block. With the exception of config, particular protocol upgrades will be available immediately.
- alloc: This section is for prefunding the accounts on the blockchain.
In order to keep our blockchain private, we need to customize the genesis block in the genesis.json configuration file:
- For the private blockchain, set homesteadblock as 0.
- It’s also very important to supply a network ID that’s different from the default value of 1 for the main Ethereum network.
- If you don’t plan to prefund the blockchain, the alloc struct can be kept blank.
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.
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.
Resources
Free Webinars on Blockchain
Here is the list of our free webinars that are highly recommended:
- Hyperledger Fabric for system admin versus developers
- How to harness blockchain for environmental and corporate sustainability
- Review of Initial Coin Offering, Security Token Offering and asset tokenization use cases and best practices
- Hyperledger Fabric Deployment on Cloud
- Hyperledger Fabric for entrepreneurship- 21 blockchain business use cases
Free Courses
Here is the list of our 10 free self-paced courses that are highly recommended:
- IT Career Roadmap Explained
- Web Design with Bootstrap
- User Experience Best Practices
- Intro to Search Engine Optimization
- Web Design with WordPress
- Introduction to Drupal CMS
- Intro to Joomla CMS
- Intro to Cybersecurity
- Introduction to Cloud Technology
- Recorded Live Webinars and Classes
Self-Paced Blockchain Courses
If you like to learn more about Hyperledger Fabric, Hyperledger Sawtooth, Ethereum or Corda, taking the following self-paced classes is highly recommended:
- Intro to Blockchain Technology
- Blockchain Management in Hyperledger for System Admins
- Hyperledger Fabric for Developers
- Intro to Blockchain Cybersecurity
- Learn Solidity Programming by Examples
- Introduction to Ethereum Blockchain Development
- Learn Blockchain Dev with Corda R3
- Intro to Hyperledger Sawtooth for System Admins
Live Blockchain Courses
If you want to master Hyperledger Fabric, Ethereum or Corda, taking the following live classes is highly recommended:
- Live and self-paced blockchain development with Ethereum
- Live and self-paced blockchain development with Hyperledger Fabric
- Live and self-paced blockchain development with Corda
- Immersive Blockchain Bootcamp with live and self-paced courses
- Live crash course for learning Ethereum with Solidity
- Live crash course for building DApps with Hyperledger Fabric
- Live crash course for building DApps with Corda
- Live full-stack blockchain development in Hyperledger and Ethereum
Articles and Tutorials on Blockchain Technology
If you like to learn more about blockchain technology and how it works, reading the following articles is highly recommended:
- History and Evolution of Blockchain Technology from Bitcoin
- Overview of Blockchain evolution and phases from Ethereum to Hyperledger
- Comprehensive overview and analysis of blockchain use cases in many industries
- Blockchain Crowdfunding Security Token or Initial Coin Offerings
- A beginner Guide to Blockchain Technology
- How Decentralized Peer-To-Peer Network Works
- How blocks are added to the blockchain
- How Public and Private Keys of Cryptography Work
- What Is A Cryptographic Hash Function
- How Digital Signature Works In Blockchain
- The role and types of consensus mechanism in blockchain
- How Proof-of-Work Consensus Works in Blockchain
- How Proof of Stake Consensus works in Blockchain
Articles and Tutorials on Ethereum and Solidity
If you like to learn more about blockchain development in Ethereum with Solidity, reading the following articles and tutorials is highly recommended:
- Review of Architecture and Components of Ethereum
- Comprehensive Blockchain Ethereum Developer Guide from Beginner to Advance Level
- How to Write Ethereum Smart Contracts with Solidity in 1 hour
- Review of Architecture and Components of Ethereum
- How Ethereum Manages Accounts
- How Ethereum Manages Transactions
- How Smart Contracts Work in Ethereum
- How Ether and Gas Work in Ethereum
- How Ethereum Virtual Machine works
- How address and wallet work in Ethereum
- How mining works in Ethereum
- List of Tools and Technologies in Ethereum Ecosystem
- Review of challenges in distributed systems
- Review of Cap Theorem in Distributed Systems
- Horizontal Scaling versus Vertical Scaling in Distributed Systems
- How to Scale up Ethereum Blockchain Applications
- Review of scaling solutions for Ethereum
- How to Manage Ethereum State Channel with Raiden
- How Plasma Chains Work in Ethereum
- How Sharding and Gasper work in Ethereum
- How Proof-of-Stack Consensus Works in Ethereum
- A roadmap for Implementing Ethereum 2.0
- How to work with Decentralized Data and Content Storage in Ethereum
- How Decentralized Messaging with Whisper Works in Ethereum
- Review of Infura for Ethereum Development
- Review of Infura Ethereum API
- How to Use Remix with Infura for Ethereum Development
- How Ethereum Client API Works
- How Ethereum IPFS Storage Works
- How to Install and Start Ethereum IPFS Storage
- How to Run Ethereum IPFS Storage
- How to Work with Ethereum Swarm Storage
- How to Install Ethereum Swarm Storage
- How to Handle Ethereum Messages with Whisper
- Review of Popular Ethereum Smart Contract Libraries
- Review of Private and Permissioned blockchain
- How to Set up a Local Private Ethereum Blockchain
- How to Run Geth on a Local Private Ethereum Blockchain
- How to Build a Local Private Ethereum Blockchain with Mining
- How to Run Geth on a Local Private Ethereum Blockchain with Mining
- How to Create an Account on a Local Private Ethereum Blockchain
- How to Use Ethereum Optional Flags with New Chains
- Review of Ethereum Options for Development and Testing
- Review of Ethereum Developer Chain Options
- Review of Ethereum API and Console Options
- Review of Ethereum Networking Options
- Review of Ethereum Transaction Pool Options
Articles and Tutorials on Hyperledger Family
If you like to learn more about blockchain development with Hyperledger, reading the following articles and tutorials is highly recommended:
- Introduction to Hyperledger Architecture, Projects, Tools and Libraries
- Complete Review of Hyperledger Fabric Architecture and Components
- Hyperledger Fabric for System Administers versus Developers
- How to use Prometheus and Grafana to monitor Hyperledger Fabric
- Blockchain Developer Guide- How to Install Hyperledger Fabric on AWS
- Blockchain Developer Guide- How to Install and work with Hyperledger Sawtooth
- Blockchain Developer Guide- How to Install Hyperledger Burrow on AWS
- Blockchain Developer Guide- How to Install Hyperledger Iroha on AWS
- Blockchain Developer Guide- How to Install Hyperledger Indy and Indy CLI on AWS
- Blockchain Developer Guide- How to Install Hyperledger Seth and Docker on AWS
- Blockchain Developer Guide- How to Configure Hyperledger Sawtooth Validator and REST API on AWS
- Blockchain Developer Guide- How to Build Transaction Processor as a Service and Python Egg for Hyperledger Sawtooth
- Blockchain Developer Guide- How to Deploy Ethereum Smart Contracts with Hyperledger Burrow
- Blockchain Developer Guide- How to Create Cryptocurrency Using Hyperledger Iroha CLI
- Blockchain Developer Guide- How to Explore Hyperledger Indy Command Line Interface
- Blockchain Developer Guide- Comprehensive Blockchain Hyperledger Developer Guide from Beginner to Advance Level
- Introduction to Hyperledger Sawtooth Blockchain Development
Articles and Tutorials on R3 Corda
If you like to learn more about blockchain development on Corda , reading the following articles and tutorials is highly recommended:
Articles and Tutorials on Other Blockchain Platforms
If you like to learn more about blockchain development in other platforms, reading the following articles and tutorials is highly recommended: