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 (How to Build a Local Private Ethereum Blockchain with Mining), we discussed how to develop a local private Ethereum network that includes mining component.

In this article, we learn how to run Geth on a local private Ethereum network that includes mining component.

Running Geth

With the genesis.json file, let’s build the first node in the private blockchain for mining.

1. Let’s navigate to the root directory and initialize the blockchain using the
genesis.json file, as follows:

$ cd hello_world_mining/data
  $ geth --datadir  hello_world_mining/data init hello_world_mining/genesis.json

To make this a bit more interesting, we will set up our own bootnode. A bootnode is a node that can be used to allow any node to join the private network for the first time and find other nodes in the network.
For example, MainnetBootnodes is the bootnode of the main Ethereum network. It is defined as follows in params/bootnodes.go:

var MainnetBootnodes = []string{
  //  Ethereum Foundation Go Bootnodes "enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c2843399 68eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d33311 63c@52.16.188.185:30303", // IE
  "enode://3f1d12044546b76342d59d4a05532c14b85aa669704bfe1f864fe07941 5aa2c02d743e03218e57a33fb94523adb54032871a6c51b2cc5514cb7c7e35b3ed0 a99@13.93.211.84:30303", // US-WEST
  …
  }

Other than MainnetBootnodes, there are also other predefined bootnodes for test networks:

  • Ropsten test network: TestnetBootnodes
  • Rinkeby test network: RinkebyBootnodes
  • Goerli test network: GoerliBootnodes
  • Experimental RLPx v5 topic-discovery network: DiscoveryV5Bootnodes

As we can see, there are the existing test networks: the Ropsten test network, the Rinkeby test network, the Goerli test network, and the experimental RLPx v5 topic-discovery network. We will talk about them in detail later on.
Geth supports bootnode creation for private networks too. You will start bootnode at the specified enode address. The following steps are for creating an enode URL and starting the bootnode.

 

One-to-One Live Blockchain Classes

Coding Bootcamps school offers One-to-One Live Blockchain Classes for Beginners.

 

2. If you type the bootnode command, you will get the following warning:

$ bootnode
  Fatal: Use -nodekey or -nodekeyhex to specify a private key.

It complains about a missing private key, which can be generated by a command;
Let’s call this key PrivateBootnode.key:

$ bootnode -genkey  PrivateBootnode.key

3. As shown in the following code block, we can check if the key was generated:

$ cat PrivateBootnode.key 15bdd11dbff8327552ac8ac7fb2c3bca4373e98657dd30d83491cea635dca903

4. We can get the enode address of the bootnode by using the -nodekey option:

$ bootnode  -nodekey PrivateBootnode.key

Alternatively, we can use the key from the previous step to generate the enode address:

$ bootnode -nodekeyhex 15bdd11dbff8327552ac8ac7fb2c3bca4373e98657dd30d83491cea635dca903  - writeaddress c25172a39c2c118290912c181b73376e4e58b8cc3b5178e4aa2f0a929e1739216c9
  baa6db990513963bcf6a3cf1652c23d5655cc637f5d611297349f887543d0

5. Now, start a new terminal session. We will use the -bootnodes flag to tell geth to use the bootnode we just created. Remember to put enode:// before the enode address:

$ cd hello_world_mining/
  $ geth --datadir data -- bootnodes=enode://c25172a39c2c118290912c181b73376e4e58b8cc3b5178e4a a2f0a929e1739216c9baa6db990513963bcf6a3cf1652c23d5655cc637f5d611297 349f887543d0@100.100.100.100:3031

Geth will create a file under hello_world_mining/data/geth.ipc. We will use this file to create a new account.

 

Next Article

In our next article (How to Create an Account on a Local Private Ethereum Blockchain), we discuss how to create an account 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:

 

Free Courses

Here is the list of our 10 free self-paced courses that are highly recommended:

 

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:

  1. Intro to Blockchain Technology
  2. Blockchain Management in Hyperledger for System Admins
  3. Hyperledger Fabric for Developers
  4. Intro to Blockchain Cybersecurity
  5. Learn Solidity Programming by Examples
  6. Introduction to Ethereum Blockchain Development
  7. Learn Blockchain Dev with Corda R3
  8. 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:

 

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:

 

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:

 

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:

 

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: