How to build an Ethereum private blockchain network using Geth (2024)

This post will discuss building a private network of multiple nodes based on Geth (the official Go implementation of the Ethereum protocol).

If the nodes of an Ethereum network are not connected to the main network or any other public network, then the network is called a private network.

We must provide our private network with a network ID not used by public networks. You can check all the public network ids at chainlist.

Sometimes network id is also referred to as chain id. Let’s move ahead and set up the private blockchain network.

Step 1: Install the geth client

The first thing we need to do is to download and install the Geth client. You should have access to geth binary before moving ahead.

Step 2: Create genesis.json

Every blockchain starts with a genesis (first) block. The genesis block is configured using a genesis.json file for a private network. Inside a new folder/directory, create a genesis.json file with the below content.

{
"config": {
"chainId": 2345,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc": {},
"coinbase": "0x0000000000000000000000000000000000000000",
"difficulty": "0x400",
"extraData": "",
"gasLimit": "0x2fefd8",
"nonce": "0x0000000000000042",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x00"
}

The most important thing here is chainId inside config. It is the network id we discussed in the previous section. There are a few more parameters required for the setup. You are not required to know them but you can read this post for details.

Step 3: Initiate the private blockchain

We have the configuration ready for the genesis block. Let’s run our first geth command to initialize the private blockchain.

geth --datadir ./node1 init genesis.json

This command will create a folder node1 in the current directory. Inside this directory, there will be a lot of folders/files created. You are not required to know them all.

Optionally, you can run the command below to access the Javascript console attached to the blockchain we created.

geth --datadir ./node1 console

Make sure you disconnect from the console by typing exit. You can also use Ctrl+d to stop.

Step 4: Add the first node to the private blockchain

To start the first node and also attach a console to it, run the below command:

geth --datadir ./node1 --syncmode "full" --port 30304 --http --http.addr "localhost" --http.port 8552 --http.api "personal,eth,net,web3,txpool,miner,admin" --http.corsdomain="*" --networkid 2345 --allow-insecure-unlock --authrpc.port 8553 console

The most important input here is networkid, representing our private blockchain’s chainId given in genesis.json. There are a few important flags passed in this call. All HTTP-related flags are for accessing the node using HTTP protocol. Let’s see the most important flags.

port: Our node is running on this port.

http.port: This is for the HTTP protocol access.

authrpc.port : This is for UDP and WS access.

We need to provide a different value for all these three ports for each node in our blockchain, as we will run all our nodes locally.

The command output should have a enode value. This value represents the node. See below code snippet and diagram for example.

self=enode://6bac6fdaa3e7bc3e15ca38559405e8db6e0b082bed5183ef6c796b806d28db41f8a9e7768546451ee832d91312fb826fd57b543be379128f3b51f8b994135717@127.0.0.1:30304
How to build an Ethereum private blockchain network using Geth (2)

Step 5: Add one more node to the private blockchain

We need a separate folder/directory for the datadir in the second node, but the genesis file will be the same. So let’s first initialize the second node. Use the below command for that:

geth --datadir ./node2 init genesis.json

To run the node, we need to change a few input parameters as discussed in the previous step. Let’s modify port, http.port and authrpc.port in the previous command. I have listed an example command below:

geth --datadir ./node2 --syncmode "full" --port 30305 --http --http.addr "localhost" --http.port 8554 --http.api "personal,eth,net,web3,txpool,miner,admin" --http.corsdomain="*" --networkid 2345 --allow-insecure-unlock --authrpc.port 8555 console

Take note of the enode value for this node also.

self=enode://2901e179d1a5c2d38b9e648406869ce5579012c04e834b8ec29103ace310964978b6dc66cfa1331f15e8af2c34a53a1756e2d0215b6800dc5300e3072be80528@127.0.0.1:30305
How to build an Ethereum private blockchain network using Geth (3)

We can repeat this process for any number of nodes as required.

Step 6: Connect node2 with node1 as peer

For this post, we will add the peer nodes using a manual process. There are ways to automatic discovery of peers. We will cover that in the next post.

Go to the node1 console and add the node2 enode value using admin.addPeer command. The command will look like the below:

admin.addPeer("enode://2901e179d1a5c2d38b9e648406869ce5579012c04e834b8ec29103ace310964978b6dc66cfa1331f15e8af2c34a53a1756e2d0215b6800dc5300e3072be80528@127.0.0.1:30305")

After running the command, Check if the peer is added successfully by running the command admin.peers. See the image below for an example.

How to build an Ethereum private blockchain network using Geth (4)

You can also run the admin.peers in the node2 console to see the enode for node1.

Step 7: Do a transaction between two accounts

There are different ways to create an account, but we will use the simplest one here. Run personal.newAccount() command on the console of both nodes and remember the Passphrase entered. You can not recover that, so note it down somewhere.

> personal.newAccount()
Passphrase:
Repeat passphrase:
INFO [05-01|14:34:37.856] Your new key was generated address=0xA6b35AE2D95bA88f853EdDC6ecEe5800bCFa2610
WARN [05-01|14:34:37.856] Please backup your key file! path=/Users/hemant.gupta/private-blockchain-work/private-blockchain-geth/node1/keystore/UTC--2023-05-01T09-04-36.868804000Z--a6b35ae2d95ba88f853eddc6ecee5800bcfa2610
WARN [05-01|14:34:37.856] Please remember your password!
"0xa6b35ae2d95ba88f853eddc6ecee5800bcfa2610"
How to build an Ethereum private blockchain network using Geth (5)

Check the output above. The command will return an address. It is the public address of your newly created account. Also, it will return the path of the private secret key file corresponding to this address. These two values combined are called public-private key pair.

See the list of accounts and their balance using below commands:

# It will return list of accounts
eth.accounts
...

#The first account is accounts[0], use that to get its balance
eth.getBalance(eth.accounts[0])

To fund the account, let’s start mining!

Go to the node1 console and type the below command to start mining. The value passed in the start method is the number of CPUs used.

miner.start(1)

Mining can be stopped at any time by command: miner.stop()

If you allow mining for some time and then check the balance of your node1 account, you will see some test ethers there.

Let’s send some ethers to the node2 account!!!

Before doing the transaction, we have to unlock the node1 account. Use the below command in the node1 console and provider the password of your node1 account.

personal.unlockAccount(eth.accounts[0], "<account-password>")

The command should return true if the account is unlocked successfully. Let’s go ahead with the transaction.

The eth.sendTransaction method is used for token transfer. It takes three values — from account, to account and token value. I am sending 4 ethers in this example.

eth.sendTransaction({from:eth.accounts[0], to:"0x52e85f4fde9ac49832b33c2f2dd3bab805a6c8c0", value: web3.toWei(4, "ether")})
INFO [05-01|14:37:48.070] Setting new local account address=0xA6b35AE2D95bA88f853EdDC6ecEe5800bCFa2610
INFO [05-01|14:37:48.070] Submitted transaction hash=0x1c0a9e1ec6284ce01534bfb5aa2b0b082e8f4e5cad2a5b641b1ef96fe2b121f4 from=0xA6b35AE2D95bA88f853EdDC6ecEe5800bCFa2610 nonce=0 recipient=0x52e85F4FDe9Ac49832B33c2F2Dd3bAb805A6C8C0 value=4,000,000,000,000,000,000
"0x1c0a9e1ec6284ce01534bfb5aa2b0b082e8f4e5cad2a5b641b1ef96fe2b121f4"
How to build an Ethereum private blockchain network using Geth (6)

You should get the transaction hash in the command output. Use this hash to know the details of the transaction by command eth.getTransaction(“<transaction-hash>”).

> eth.getTransaction("0x1c0a9e1ec6284ce01534bfb5aa2b0b082e8f4e5cad2a5b641b1ef96fe2b121f4")
{
blockHash: "0x8df6e10ecccc3d3973c33d538d905bb9a4362b819d0e8a84419d2ec713efd7b8",
blockNumber: 45,
chainId: "0x929",
from: "0xa6b35ae2d95ba88f853eddc6ecee5800bcfa2610",
gas: 21000,
gasPrice: 1000000000,
hash: "0x1c0a9e1ec6284ce01534bfb5aa2b0b082e8f4e5cad2a5b641b1ef96fe2b121f4",
input: "0x",
nonce: 0,
r: "0x2b129ec1b410716b4ba7288b9e88274c389c269b65461bab50a8eba685e1004",
s: "0x21a71422f4e5316450122311220146c66d3c65c8a3549c62406dfe198977f8af",
to: "0x52e85f4fde9ac49832b33c2f2dd3bab805a6c8c0",
transactionIndex: 0,
type: "0x0",
v: "0x1276",
value: 4000000000000000000
}

Don’t forget to go to the node2 console and check the balance.

> eth.getBalance(eth.accounts[0])
4000000000001000000

This post focused on executing all the steps by running the required geth commands. It helps in building the fundamentals. I will cover building the private blockchain using docker in the next post. Be ready to get surprised! It is going to easy and fun.

Happy BUIDLing.

References:

Geth Homepage: https://geth.ethereum.org/

Geth Download: https://geth.ethereum.org/downloads

Ethereum Private Networks: https://geth.ethereum.org/docs/fundamentals/private-network

How to build an Ethereum private blockchain network using Geth (2024)

FAQs

How to build an Ethereum private blockchain network using Geth? ›

On Windows, Geth installation is as simple as extracting geth.exe from your chosen OS. The download page provides an installer as well as a zip file. The installer puts geth into your PATH automatically. The zip file contains the command .exe files and can be used without installing.

How to create a private blockchain using Geth? ›

Below is the step-by-step guide to setting up a private Ethereum network.
  1. Step 1: Install Geth on Your System. ...
  2. Step 2: Create a Folder For Private Ethereum. ...
  3. Step 3: Create a Genesis Block. ...
  4. Step 4: Execute genesis file. ...
  5. Step 5: Initialize the private network. ...
  6. Step 6: Create an Externally owned account(EOA)
Apr 24, 2023

How to build a private blockchain network? ›

How to Create a Private Blockchain Platform?
  1. Step 1: Understand Your Business Goals. ...
  2. Step 2: Hiring Blockchain Developers. ...
  3. Step 3: Building a Private Chain. ...
  4. Step 4: Planning for the Required Decentralized Apps. ...
  5. Step 5: Start Prototyping. ...
  6. Step 6: Creating the Backend Part. ...
  7. Step 7: Deployment of Apps to Your Blockchain.
Apr 1, 2024

How to setup geth? ›

On Windows, Geth installation is as simple as extracting geth.exe from your chosen OS. The download page provides an installer as well as a zip file. The installer puts geth into your PATH automatically. The zip file contains the command .exe files and can be used without installing.

How to set up a private ethereum blockchain and deploy a solidity smart contract on the blockchain? ›

Create and Deploy your Smart Contract
  1. Step 1: Connect to the Ethereum network. ...
  2. Step 2: Create your app (and API key) ...
  3. Step 3: Create an Ethereum account (address) ...
  4. Step 4: Add ether from a Faucet. ...
  5. Step 5: Check your Balance. ...
  6. Step 6: Initialize our project. ...
  7. Step 7: Download Hardhat. ...
  8. Step 8: Create Hardhat project.

What are the requirements for Geth Ethereum? ›

Hardware Requirements
Archive NodeFull Node
DiskAt least 2.2TB (TLC NVMe recommended)At least 1.2TB (TLC NVMe recommended)
Memory8GB+8GB+
CPUHigher clock speed over core countHigher clock speeds over core count
BandwidthStable 24Mbps+Stable 24Mbps+

Which Geth command is used to create a new account in blockchain? ›

Geth contains a number of commands and options. [02:09 - 02:15] We can see the list by running --help. One of the first things we're going to need are accounts. [02:16 - 02:25] We can create an account like so. /bin/geth-dur=data-dur, account new.

How to create a private network? ›

Select Settings > Network & internet > Wi-Fi. On the Wi-Fi settings screen, select Manage known networks, and select the network you're connected to. On the Wi-Fi network screen, under Network profile type, select Public (Recommended) or Private.

What is an example of a private blockchain network? ›

Unlike public blockchains where the identity of people are largely anonymous, the identity of people involved on a private blockchain is known. Examples of private blockchains include Hyperledger and Corda.

How to create a blockchain like Ethereum? ›

How to Create Own Blockchain Network
  1. Step 1: Identify a Suitable Use-case. ...
  2. Step 2: Identify the Most Suitable Consensus Mechanism. ...
  3. Step 3: Identify the Most Suitable Platform. ...
  4. Step 4: Designing the Nodes. ...
  5. Step 5: Design the Blockchain Instance. ...
  6. Step 6: Building the APIs.

What is geth in Ethereum? ›

Geth (Go-Ethereum) is a crucial component of the Ethereum ecosystem. As a command-line interface, Geth provides a gateway for users and developers to interact with the Ethereum blockchain. It serves as a robust platform for running Ethereum nodes, executing smart contracts, and managing digital assets.

What are the requirements for Geth? ›

Fast CPU with 4+ cores. High Ghz/Core is important, starting at 3.5 Ghz and more. 16 GB RAM minimum requirement, 32GB is recommended. Storage requirements depend on the client software ( Geth consumes ~15+ TB, while Erigon requires more than 2TB disk space).

How to interact with geth? ›

Once the TestRPC node starts or the full Ethereum node is synchronized to the blockchain, you can use the GETH program to connect to it and send commands and interactions to the network. All you need to do is to attach the GETH command to the node by specifying the node's IP address.

How to build a private Ethereum network? ›

Setup private Ethereum network in cloud
  1. Install go (to each node):
  2. Download and build go-ethereum (on each node):
  3. Setup ethstats.
  4. Setup seal-node-n (repeat to all seal nodes)
  5. Create genesis.json using puppeth (run puppeth on stats-node and follow CLI instruction to generate genesis file)
  6. Init seal-node-n.
  7. Run boot-node:
Feb 13, 2024

How to build a blockchain application from scratch? ›

8 Steps to Develop a Blockchain Application
  1. Step 1: Analyze the Industry for App Development. ...
  2. Step 2: Come Up with an Idea. ...
  3. Step 3: Do Competitor Research. ...
  4. Step 4: Choose a Platform for Your Blockchain Project. ...
  5. Step 5: Design Your Blockchain App. ...
  6. Step 6: Start the Development and Testing Process.
Jun 17, 2024

How to deploy smart contract on Ethereum testnet? ›

Deploying Contract
  1. Connecting to the Ethereum Network.
  2. Create Your App and Obtain an API Key.
  3. Setting Up Your Ethereum Account.
  4. Adding Ether from a Sepolia Faucet.
  5. Initiating Our Project.
  6. Downloading and Setting Up Hardhat.
  7. Creating a Hardhat Project.
  8. Creating Project Folders.

Can I have a private blockchain? ›

Public vs.

Public blockchains allow anyone access; private blockchains are available to selected or authorized users; permissioned blockchains have different levels of user permissions or roles. Many cryptocurrencies are built on open-source, public blockchains.

How do I create a private key in blockchain? ›

The crypto wallet is a software program that stores public and private keys and cooperates with the blockchain to allows users to send and receive digital currency online. first of all, you will need to set up a bitcoin wallet which will then randomly generate a 256 bit long number and This will be your private key.

How to set up a private Ethereum blockchain proof of authority with go Ethereum part 2? ›

Setup private Ethereum network in cloud
  1. Install go (to each node):
  2. Download and build go-ethereum (on each node):
  3. Setup ethstats.
  4. Setup seal-node-n (repeat to all seal nodes)
  5. Create genesis.json using puppeth (run puppeth on stats-node and follow CLI instruction to generate genesis file)
  6. Init seal-node-n.
  7. Run boot-node:
Feb 13, 2024

How much does it cost to build a private blockchain? ›

How much does creating a private blockchain cost? The price of creating a private blockchain might differ based on the project's needs. The average cost of creating a private blockchain, however, can be between $10,000 and $100,000, while a more complicated application can cost up to $250,000.

Top Articles
Virtual Card Processing: What to Know About Accepting Virtual Cards | Versapay
Password and Secrets Management - Keeper Security
Foxy Roxxie Coomer
Swimgs Yuzzle Wuzzle Yups Wits Sadie Plant Tune 3 Tabs Winnie The Pooh Halloween Bob The Builder Christmas Autumns Cow Dog Pig Tim Cook’s Birthday Buff Work It Out Wombats Pineview Playtime Chronicles Day Of The Dead The Alpha Baa Baa Twinkle
J & D E-Gitarre 905 HSS Bat Mark Goth Black bei uns günstig einkaufen
The Atlanta Constitution from Atlanta, Georgia
What Are the Best Cal State Schools? | BestColleges
Here are all the MTV VMA winners, even the awards they announced during the ads
South Park Season 26 Kisscartoon
Kris Carolla Obituary
Noaa Weather Philadelphia
GAY (and stinky) DOGS [scat] by Entomb
MADRID BALANZA, MªJ., y VIZCAÍNO SÁNCHEZ, J., 2008, "Collares de época bizantina procedentes de la necrópolis oriental de Carthago Spartaria", Verdolay, nº10, p.173-196.
Natureza e Qualidade de Produtos - Gestão da Qualidade
Where's The Nearest Wendy's
123Moviescloud
Diablo 3 Metascore
Summer Rae Boyfriend Love Island – Just Speak News
Gon Deer Forum
Shannon Dacombe
Operation Cleanup Schedule Fresno Ca
Pac Man Deviantart
Justified Official Series Trailer
Golden Abyss - Chapter 5 - Lunar_Angel
Aris Rachevsky Harvard
Tyrone Unblocked Games Bitlife
Sec Baseball Tournament Score
Cookie Clicker Advanced Method Unblocked
Sorrento Gourmet Pizza Goshen Photos
Znamy dalsze plany Magdaleny Fręch. Nie będzie nawet chwili przerwy
Cars & Trucks - By Owner near Kissimmee, FL - craigslist
Egusd Lunch Menu
As families searched, a Texas medical school cut up their loved ones
Horses For Sale In Tn Craigslist
Craigslist Comes Clean: No More 'Adult Services,' Ever
Obituaries, 2001 | El Paso County, TXGenWeb
Co10 Unr
Meggen Nut
Purdue Timeforge
Used 2 Seater Go Karts
Brenda Song Wikifeet
Breckie Hill Fapello
Nsu Occupational Therapy Prerequisites
Old Peterbilt For Sale Craigslist
Workday Latech Edu
Marcus Roberts 1040 Answers
Low Tide In Twilight Manga Chapter 53
Rage Of Harrogath Bugged
Craigslist Binghamton Cars And Trucks By Owner
Germany’s intensely private and immensely wealthy Reimann family
Service Changes and Self-Service Options
Latest Posts
Article information

Author: Roderick King

Last Updated:

Views: 5846

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.