![](https://coding-bootcamps.com/wp-content/uploads/2024/01/99-1.jpg)
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 Set up a Local Private Ethereum Blockchain), we discussed how to set up a local private Ethereum network.
In this article, we learn how to setup and run Geth on a local private Ethereum network.
Running Geth
Once the genegsis.json file has been created, you are ready to start the private Ethereum blockchain. We will start the node in one terminal/process where we can see the logs being written to stdout. In the second terminal, we will use the geth console to get the console. There are advantages of using two terminals:
- Logs from the first terminal are written to stdout instead of being redirected. We know that everything is functional.
- Closing the console in the second terminal doesn’t terminate the geth syncing process.
Now, let’s see how we can run geth:
1. In dir hello_world, we will start the first node by running the following command:
$ geth --datadir block_0 --identity node_0 --verbosity 6 -- ipcdisable --port 30398 --rpcport 8171
The following is a list of a few command-line options:
- –datadir: It specifies the directory for the database and Keystore to be stored. In our case, it is set as block_0, which means the database with the first genesis block on our private blockchain was created under the block_0 directory. Everything geth persists now will write to block_0. The default datadir value is listed in the following table:
Operating system | Datadir |
Mac | ~/Library/Ethereum |
Windows | %APPDATA%\Ethereum |
Linux | ~/.ethereum |
- –identity specifies a custom node name.
- –verbosity defines the log level.
- –ipcdisable disables the IPC-RPC server during the startup.
- –port is the network listening port number for the node; the default value is 30303.
- –rpcport specifies the http-rpc server listening port number; the default is 8545.
2. We will use the geth console to start a session of an interactive JavaScript environment, where we will interact with the first node that we just created. It will show us something like the following:
$ geth console Welcome to the Geth JavaScript console! instance: Geth/node_0/v1.8.22-stable/darwin-amd64/go1.11.5 modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
3. In the console, we can obtain all the node information with
the admin.nodeInfo command. We will need enode later when we want to implement it in the second node as it is a peer to the second node. To check the enode of the first node, we can type in the following command:
One-to-One Live Blockchain Classes
Coding Bootcamps school offers One-to-One Live Blockchain Classes for Beginners.
admin.nodeInfo.enode "enode://4202d9ac5c1c7c8eea8ae56dbc881fb61230c7447d81b964345bba3841 684f8449e6dce625552c3c881622a6f3dabeee596f3ff61dd212ad14cfb6f687793 ef1@100.100.100.100:30398"
Note that we assume that the 30398 port is open for listening. This might not work for users who have their firewall enabled. I used a fake IP address 100.100.100.100, and it will be used several times in this section. To find your own IP address, you can use the following command in your terminal:
$ ifconfig|grep netmask|awk '{print $2}'
4. Leave the terminal open or save the enode information for the first node somewhere. So far, we have a single node in the network. If we check on peers now, it will be an empty list, as follows:
admin.peers[]
To run multiple nodes of a local blockchain, we will need to make sure they are running on a different port. We will use a different port for the second node by putting down a different value in –port and –rpcport.
5. Let’s run the second node with a slightly different command, as follows:
$ geth --datadir block_1 --identity node_1 --verbosity 6 -- ipcdisable --port 30399 --rpcport 8173 console 2>> logs/second_node.log
We have two nodes running, but they are unaware of each other’s existence. In order to create a peer-to-peer network with these two nodes, we can use the addPeer command.
6. In the current console for the second node, we will add the first node as a peer to the second node, as follows:
>admin.addPeer("enode://4202d9ac5c1c7c8eea8ae56dbc881fb61230c7447d8 1b964345bba3841684f8449e6dce625552c3c881622a6f3dabeee596f3ff61dd212 ad14cfb6f687793ef1@100.100.100.100:30398") True
Using admin.addPeer to add static nodes at runtime is just adding nodes ephemerally, instead of permanently. If you have restarted the process, you will notice the peer you’ve added is gone in a new session. Admin.addPeer is usually used for debugging purposes. If you would like to add a peer permanently, the peer needs to be manually configured in the geth config file called static- nodes.json, under the <datadir>/geth/ path, as shown in the following example:
[ "enode://4202d9ac5c1c7c8eea8ae56dbc881fb61230c7447d81b964345bba3841 684f8449e6dce625552c3c881622a6f3dabeee596f3ff61dd212ad14cfb6f687793 ef1@100.100.100.100:30398" ]
If you have more static nodes to add, you can keep appending some enode URLs to the static-nodes.json file, as shown in the following example:
[ "enode://4202d9ac5c1c7c8eea8ae56dbc881fb61230c7447d81b964345bba3841 684f8449e6dce625552c3c881622a6f3dabeee596f3ff61dd212ad14cfb6f687793 ef1@100.100.100.100:30398", "enode://pubkey@ip:port", ... ]
7. The console returns true when it is successfully executed. We will use the following command to test the connection:
admin.peers...
Furthermore, admin.peers will list out the detailed information of the first node; we won’t list them all here.
As you can see in the following code snippet, net.peerCount will show only 1 peer in your local blockchain network now:
net.peerCount1
Check if the network is listening, with the help of the following command:
net.listeningtrue
That is all you need to start a private blockchain. As we discussed before, you can configure your development tools to connect to the local blockchain for testing and debugging before you deploy your smart contracts to testnet or mainnet.
Next Article
In our next article (How to Build a Local Private Ethereum Blockchain with Mining), we discuss how to develop a local private Ethereum network that includes mining component.
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: