Creating a Private Network in Ethereum

Natnael Melese
8 min readNov 12, 2022

--

Create your first private network in Ethereum

Part 1 of this article:

What is Ethereum Private Network?

A blockchain that is entirely private and separate from the main Ethereum network is known as an Ethereum Private Network. Organizations mostly use the Ethereum Private Network to limit Blockchain read access. The only nodes allowed to access this Blockchain will be those with the appropriate permissions. The nodes in this network are not linked to the nodes in the main network, and they can only communicate with other nodes in this private Blockchain.

Installing Ethereum on Ubuntu

To create an Ethereum Private Network, we first need to have Ethereum installed in our system. In this section of the Ethereum Private Network Tutorial, you will learn how to install Ethereum on Ubuntu.

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository -y ppa:ethereum/ethereum
$ sudo apt-get update
$ sudo apt-get install ethereum

Creating Accounts For Ethereum Private Network

Before creating new accounts, let us create a new directory. By using the below commands:

$ mkdir eth-private
$ cd eth-private

Let’s create two accounts:

$ mkdir node0 node1
$ geth --datadir ./node0 account new
$ geth --datadir ./node0 account new

Do not forget both passphrases! Save these addresses somewhere because we will be using these further.

Creating Genesis File

The attributes that characterize the Blockchain are contained in a Genesis file. As the starting point of the Blockchain, a Genesis file must be created in order to construct a Blockchain. Let’s build the Genesis file right away.

We will be using Puppeth.

Puppeth lets you create a new Ethereum network down to the genesis block, bootnodes, miners, and ethstats servers without the hassle that it would normally entail.

┌──(n㉿kali)-[~/Documents/10_Academy/GethPoA/eth-private]
└─$ puppeth
+-----------------------------------------------------------+
| Welcome to puppeth, your Ethereum private network manager |
| |
| This tool lets you create a new Ethereum network down to |
| the genesis block, bootnodes, miners and ethstats servers |
| without the hassle that it would normally entail. |
| |
| Puppeth uses SSH to dial in to remote servers, and builds |
| its network components out of Docker containers using the |
| docker-compose toolset. |
+-----------------------------------------------------------+

Please specify a network name to administer (no spaces, hyphens or capital letters please)
> testnetwork

Sweet, you can set this via --network=testnetwork next time!

INFO [11-12|17:17:29.433] Administering Ethereum network name=testnetwork
WARN [11-12|17:17:29.470] No previous configurations found path=/home/n/.puppeth/testnetwork

What would you like to do? (default = stats)
1. Show network stats
2. Configure new genesis
3. Track new remote server
4. Deploy network components
>

By selecting option 2 we configure can create new genesis file

What would you like to do? (default = stats)
1. Show network stats
2. Configure new genesis
3. Track new remote server
4. Deploy network components
> 2

What would you like to do? (default = create)
1. Create new genesis from scratch
2. Import already existing genesis
> 1

Which consensus engine to use? (default = clique)
1. Ethash - proof-of-work
2. Clique - proof-of-authority
> 2

How many seconds should blocks take? (default = 15)
> 15

Which accounts are allowed to seal? (mandatory at least one)
> 0x

Now we use the previous account addresses.

Which accounts are allowed to seal? (mandatory at least one)
> 0x2Bd22E105E6Bf66e3748a3be2d94099572E1bd35
> 0x2E0A40623aE4671cD934744784B63a948f450d83
> 0x

Which accounts should be pre-funded? (advisable at least one)
> 0x2E0A40623aE4671cD934744784B63a948f450d83
> 0x2Bd22E105E6Bf66e3748a3be2d94099572E1bd35
> 0x
Should the precompile-addresses (0x1 .. 0xff) be pre-funded with 1 wei? (advisable yes)
> y

Specify your chain/network ID if you want an explicit one (default = random)
> 202111

Save the genesis file.

What would you like to do? (default = stats)
1. Show network stats
2. Manage existing genesis
3. Track new remote server
4. Deploy network components
> 2

1. Modify existing configurations
2. Export genesis configurations
3. Remove genesis configuration
> 2

Which folder to save the genesis spec into? (default = current)
Will create testnetwork.json
>
INFO [11-12|17:25:14.267] Saved native genesis chain spec path=testnetwork.json

testnetwork.json has been created inside the eth-private directory.

Instantiating Data Directory

Before starting the Blockchain, we have to instantiate the data directory. The Data Directory is the directory where the data related to the Blockchain is stored. To instantiate the data directory, run the following command:

┌──(n㉿kali)-[~/Documents/10_Academy/GethPoA/eth-private]
└─$ geth --datadir ./node0 init ./testnetwork.json
INFO [11-12|17:29:41.814] Maximum peer count ETH=50 LES=0 total=50
INFO [11-12|17:29:41.816] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [11-12|17:29:41.833] Set global gas cap cap=50,000,000
INFO [11-12|17:29:41.835] Allocated cache and file handles database=/home/n/Documents/10_Academy/GethPoA/eth-private/node0/geth/chaindata cache=16.00MiB handles=16
INFO [11-12|17:29:44.212] Opened ancient database database=/home/n/Documents/10_Academy/GethPoA/eth-private/node0/geth/chaindata/ancient/chain readonly=false
INFO [11-12|17:29:44.212] Writing custom genesis block
INFO [11-12|17:29:44.283] Persisted trie from memory database nodes=357 size=50.72KiB time=5.343584ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [11-12|17:29:44.286] Successfully wrote genesis state database=chaindata hash=afbf4f..643643
INFO [11-12|17:29:44.286] Allocated cache and file handles database=/home/n/Documents/10_Academy/GethPoA/eth-private/node0/geth/lightchaindata cache=16.00MiB handles=16
INFO [11-12|17:29:45.014] Opened ancient database database=/home/n/Documents/10_Academy/GethPoA/eth-private/node0/geth/lightchaindata/ancient/chain readonly=false
INFO [11-12|17:29:45.014] Writing custom genesis block
INFO [11-12|17:29:45.050] Persisted trie from memory database nodes=357 size=50.72KiB time=1.430879ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [11-12|17:29:45.051] Successfully wrote genesis state database=lightchaindata hash=afbf4f..643643

┌──(n㉿kali)-[~/Documents/10_Academy/GethPoA/eth-private]
└─$ geth --datadir ./node1 init ./testnetwork.json
INFO [11-12|17:29:56.570] Maximum peer count ETH=50 LES=0 total=50
INFO [11-12|17:29:56.573] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [11-12|17:29:56.578] Set global gas cap cap=50,000,000
INFO [11-12|17:29:56.582] Allocated cache and file handles database=/home/n/Documents/10_Academy/GethPoA/eth-private/node1/geth/chaindata cache=16.00MiB handles=16
INFO [11-12|17:29:58.454] Opened ancient database database=/home/n/Documents/10_Academy/GethPoA/eth-private/node1/geth/chaindata/ancient/chain readonly=false
INFO [11-12|17:29:58.454] Writing custom genesis block
INFO [11-12|17:29:58.490] Persisted trie from memory database nodes=357 size=50.72KiB time=5.732143ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [11-12|17:29:58.493] Successfully wrote genesis state database=chaindata hash=afbf4f..643643
INFO [11-12|17:29:58.493] Allocated cache and file handles database=/home/n/Documents/10_Academy/GethPoA/eth-private/node1/geth/lightchaindata cache=16.00MiB handles=16
INFO [11-12|17:29:59.035] Opened ancient database database=/home/n/Documents/10_Academy/GethPoA/eth-private/node1/geth/lightchaindata/ancient/chain readonly=false
INFO [11-12|17:29:59.035] Writing custom genesis block
INFO [11-12|17:29:59.068] Persisted trie from memory database nodes=357 size=50.72KiB time=4.890809ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [11-12|17:29:59.071] Successfully wrote genesis state database=lightchaindata hash=afbf4f..643643

Create a boot node

A boot node is a node that serves just as the first connection point through which an Ethereum node connects to other nodes. It’s basically a relayer of information helping nodes connect.

Creation and running of a boot node is done as follows:

$ bootnode --genkey=boot.key

Now a boot.key file will be created inside eth-private directory

┌──(n㉿kali)-[~/Documents/10_Academy/GethPoA/eth-private]
└─$ bootnode --nodekey=boot.key
enode://ae4d706f1d2141ac7de0622f87b4c23d988c272c6a31ff058e38ed8deb1930a9a4d19c5396a731476c81c4abfc3c8c1537f8b8b5448cb55d41ff0758daa5660d@127.0.0.1:0?discport=30301
Note: you're using cmd/bootnode, a developer tool.
We recommend using a regular node as bootstrap node for production deployments.
INFO [11-12|17:36:19.255] New local node record seq=1,668,292,579,254 id=618e42e8fa53b953 ip=<nil> udp=0 tcp=0

Remember using cmd/bootnode is for development purpose only.

Start individula nodes

┌──(n㉿kali)-[~/Documents/10_Academy/GethPoA/eth-private]
└─$ geth --datadir ./node1 --port 30302 --http --http.addr 'localhost' --http.port 8545 --http.api 'personal,db,eth,net,web3,txpool,miner' --bootnodes ' ' --networkid 202111 --allow-insecure-unlock --password 123456 --mine console
INFO [11-12|17:40:00.485] Maximum peer count ETH=50 LES=0 total=50
INFO [11-12|17:40:00.486] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [11-12|17:40:00.489] Set global gas cap cap=50,000,000
INFO [11-12|17:40:00.491] Allocated trie memory caches clean=154.00MiB dirty=256.00MiB
INFO [11-12|17:40:00.500] Allocated cache and file handles database=/home/n/Documents/10_Academy/GethPoA/eth-private/node1/geth/chaindata cache=512.00MiB handles=524,288
INFO [11-12|17:40:00.884] Opened ancient database database=/home/n/Documents/10_Academy/GethPoA/eth-private/node1/geth/chaindata/ancient/chain readonly=false
INFO [11-12|17:40:00.914]
INFO [11-12|17:40:00.914] ---------------------------------------------------------------------------------------------------------------------------------------------------------
INFO [11-12|17:40:00.914] Chain ID: 202111 (unknown)
INFO [11-12|17:40:00.914] Consensus: Clique (proof-of-authority)
INFO [11-12|17:40:00.915]
INFO [11-12|17:40:00.915] Pre-Merge hard forks:
INFO [11-12|17:40:00.915] - Homestead: 0 (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/homestead.md)
INFO [11-12|17:40:00.915] - Tangerine Whistle (EIP 150): 0 (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/tangerine-whistle.md)
INFO [11-12|17:40:00.915] - Spurious Dragon/1 (EIP 155): 0 (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)
INFO [11-12|17:40:00.915] - Spurious Dragon/2 (EIP 158): 0 (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)
INFO [11-12|17:40:00.915] - Byzantium: 0 (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/byzantium.md)
INFO [11-12|17:40:00.915] - Constantinople: 0 (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/constantinople.md)
INFO [11-12|17:40:00.915] - Petersburg: 0 (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/petersburg.md)
INFO [11-12|17:40:00.915] - Istanbul: 0 (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/istanbul.md)
INFO [11-12|17:40:00.915] - Berlin: <nil> (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/berlin.md)
INFO [11-12|17:40:00.915] - London: <nil> (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/london.md)
INFO [11-12|17:40:00.916]
INFO [11-12|17:40:00.916] The Merge is not yet available for this network!
INFO [11-12|17:40:00.916] - Hard-fork specification: https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md
INFO [11-12|17:40:00.916] ---------------------------------------------------------------------------------------------------------------------------------------------------------
INFO [11-12|17:40:00.916]
INFO [11-12|17:40:00.917] Initialising Ethereum protocol network=202,111 dbversion=<nil>
INFO [11-12|17:40:00.920] Loaded most recent local header number=0 hash=afbf4f..643643 td=1 age=20m44s
INFO [11-12|17:40:00.920] Loaded most recent local full block number=0 hash=afbf4f..643643 td=1 age=20m44s
INFO [11-12|17:40:00.920] Loaded most recent local fast block number=0 hash=afbf4f..643643 td=1 age=20m44s
WARN [11-12|17:40:00.921] Failed to load snapshot, regenerating err="missing or corrupted snapshot"
INFO [11-12|17:40:00.922] Rebuilding state snapshot
INFO [11-12|17:40:00.924] Resuming state snapshot generation root=d61525..8ca6b4 accounts=0 slots=0 storage=0.00B dangling=0 elapsed=1.295ms
INFO [11-12|17:40:00.924] Regenerated local transaction journal transactions=0 accounts=0
INFO [11-12|17:40:00.925] Stored checkpoint snapshot to disk number=0 hash=afbf4f..643643
INFO [11-12|17:40:00.936] Generated state snapshot accounts=258 slots=0 storage=9.64KiB dangling=0 elapsed=13.505ms
INFO [11-12|17:40:00.958] Gasprice oracle is ignoring threshold set threshold=2
WARN [11-12|17:40:00.958] Error reading unclean shutdown markers error="leveldb: not found"
WARN [11-12|17:40:00.958] Engine API enabled protocol=eth
WARN [11-12|17:40:00.958] Engine API started but chain not configured for merge yet
INFO [11-12|17:40:00.958] Starting peer-to-peer node instance=Geth/v1.10.26-stable-e5eb32ac/linux-amd64/go1.18.5
INFO [11-12|17:40:01.143] New local node record seq=1,668,292,801,140 id=5468bc8adfe4f5ed ip=127.0.0.1 udp=30302 tcp=30302
INFO [11-12|17:40:01.143] Started P2P networking self=enode://8af8b4856ebed204ef2ab9b0d78ca585df64d5d5de264b941a874fb27f2f8eac897bb46aeff6eab16e3eefdd57f696d65b8d62b5faf75c03caa171593737eed1@127.0.0.1:30302
INFO [11-12|17:40:01.198] IPC endpoint opened url=/home/n/Documents/10_Academy/GethPoA/eth-private/node1/geth.ipc
ERROR[11-12|17:40:01.198] Unavailable modules in HTTP API list unavailable=[db] available="[admin debug web3 eth txpool personal clique miner net]"
INFO [11-12|17:40:01.199] Generated JWT secret path=/home/n/Documents/10_Academy/GethPoA/eth-private/node1/geth/jwtsecret
INFO [11-12|17:40:01.274] HTTP server started endpoint=127.0.0.1:8545 auth=false prefix= cors= vhosts=localhost
INFO [11-12|17:40:01.274] WebSocket enabled url=ws://127.0.0.1:8551
INFO [11-12|17:40:01.274] HTTP server started endpoint=127.0.0.1:8551 auth=true prefix= cors=localhost vhosts=localhost
INFO [11-12|17:40:01.274] Transaction pool price threshold updated price=0
INFO [11-12|17:40:01.274] Updated mining threads threads=0
INFO [11-12|17:40:01.274] Transaction pool price threshold updated price=1,000,000,000
INFO [11-12|17:40:01.274] Etherbase automatically configured address=0x2E0A40623aE4671cD934744784B63a948f450d83
INFO [11-12|17:40:01.274] Commit new sealing work number=1 sealhash=1cdcaf..ddb826 uncles=0 txs=0 gas=0 fees=0 elapsed="192.008µs"
WARN [11-12|17:40:01.274] Block sealing failed err="authentication needed: password or unlock"
INFO [11-12|17:40:01.274] Commit new sealing work number=1 sealhash=1cdcaf..ddb826 uncles=0 txs=0 gas=0 fees=0 elapsed="434.581µs"
Welcome to the Geth JavaScript console!

instance: Geth/v1.10.26-stable-e5eb32ac/linux-amd64/go1.18.5
coinbase: 0x2e0a40623ae4671cd934744784b63a948f450d83
at block: 0 (Sat Nov 12 2022 17:19:16 GMT-0500 (EST))
datadir: /home/n/Documents/10_Academy/GethPoA/eth-private/node1
modules: admin:1.0 clique:1.0 debug:1.0 engine:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

To exit, press ctrl-d or type exit
>net.peerCount
0
> eth.accounts
["0x2e0a40623ae4671cd934744784b63a948f450d83"]
>

Now you can access all the Ethereum API which hase set functions to invoke operations ,access data, and store data.

  • admin.nodeInfo.enode
  • net.listening
  • net.peerCount
  • admin.peers
  • eth.coinbase
  • eth.getBalance(eth.coinbase)
  • personal
  • eth.accounts
  • miner.setEtherbase(web3.eth.accounts[0])
  • miner.setEtherbase(“0x2Bd22E105E6Bf66e3748a3be2d94099572E1bd35”)
  • miner.start()
  • miner.stop()
  • miner.hashrate
  • eth.getBlock(0)
  • eth.getBlock(“latest”)
  • eth.blockNumber
  • web3.eth.getBlock(BLOCK_NUMBER).hash
  • eth.syncing
  • debug.verbosity(6) // highest logging level, 3 is default

More API functions

References

  1. https://www.sitepoint.com/puppeth-introduction/
  2. https://github.com/ethereum/wiki/wiki/JSON-RPC
  3. https://geth.ethereum.org/docs/rpc/ns-admin
  4. https://github.com/puppeth

--

--

Natnael Melese

A Computer Programmer and an aspiring Machine Learning Engineer. My interests include programming, mathematics, AI research, and theoretical computer science.