How to mount a private blockchain with Ethereum ?
Hi guys,
Here we will cover the following subject : How to mount a private blockchain ?
A small remind
As a reminder, blockchain is also known as a distributed ledger technologies (at least for some blockchains like bitcoin and monero). It means that the same database is cloned on machines around the world, and synchronized with a P2P-like network.
You just need to need to run a node and synchronize the data with the network. Most of the blockchain that are used is public : it means you can replicate the database freely and become a node.
We must also not confuse public and transparency, since some blockchains blur transactions (like blockchains running under cryptonight).
Running a private blockchain ?
If we turn the question, running a private blockchain means that you have control on read and/or write rights of the database. Digging more, it means that you controls nodes (who can replicate ?) and the consensus algorithm process. For the last one, you need to choose a right one, since it is not especially worth it to choose a Proof-Of-Work consensus algorithm in a private distributed ledger.
The complexity of creating a private blockchain depends on your choice :
- Write from scratch your own implementation. Surely the harder way to aim that goal ^^
- Use an existing blockchain to create your own and have control on read/write rights. From here, we can subdivide this into :
- Forks an existing blockchain and re-work it. This part need to have blockchain and coding knownledge (Since most of blockchain are implemented in C++).
- Some blockchains give you the tools to implement your own easily, as for Ethereum.
We will see here how to create one with Ethereum.
Ethereum
Ethereum has appeared with a crowfunding in 2014. One of the main interesting functionnality is to deploy smart contract, a small piece of code that will be run on EVM nodes, a machine turing deterministic.
To mount a node, you have many implementation of the Ethereum client. The 2 most used is Parity (Rust Language) and Geth (for Go).
I will use Geth, since it is the most used and easy to use.
How to use Geth ?
Geth is relatively easy to use. you can download it here : https://geth.ethereum.org/downloads/
You will see a baunch of tool, but we will use only geth here.
If you execute geth without arguments, it will mount a node on the Main network (the production environment in other words).
You cannot interact with the node, it will only running it and logging messages on the console.
# Windows Command Line - Adapt to your OS
C:/Users/Defalt/Desktop/Geth/> ./geth.exe
If you wish to use the console, you have to pass the console argument :
# Windows Command Line - Adapt to your OS
C:/Users/Defalt/Desktop/Geth/> ./geth.exe console
Then from here, you can interact with the server node.
So how to mount a private blockchain ?
For geth advertised users, as you know, we can mount our node with the network id argument :
# Windows Command Line - Adapt to your OS
C:/Users/Defalt/Desktop/Geth/> ./geth.exe --help
...
--networkid value Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby) (default: 1)
...
In fact, creating your own blockchain is to position the networkid with an id that is not used. Think the networkid as a universe, composed by severals nodes that have set this id.
But this is not enough to create your own blockchain : we need to create the blockchain database, since it is a new universe.
How to create the database ?
A blockchain database is chain of block, hence the name. A block contains severals transactions. A transaction represent a exchange between two parties.
The first block of a blockchain is named Genesis block. This block init the blockchain database, and the next block that will be mint will be added after this block, and so on. Remember that Ethereum actually use a Proof-Of-Work algorithm consensus and will swap to Proof-Of-Stake. If you are not familiar with these notions, i invite you to search more on internet.
Thankfully, Geth allows us to create easily the genesis block.
1. Create genesis file
Create the directory context :
# Windows Command Line - Adapt to your OS
mkdir privatechain
cd privatechain
2. Create genesis file
Create a new json file (like genesis.json) with the following content :
{
"config": {
"chainId": 2000, // this is the network id
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : { // you can put an empty json here - alloc is used to allocate ether to an address
"8cc64acb321977fe191cbc35728ee0da77989d6b": { //The address that will receive
"balance": "100000000000000000000000" //The amount in Wei
},
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x20000",
"extraData" : "",
"gasLimit" : "0x2fefd8",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
If you want to know more about parameters, follow this link :
https://gist.github.com/0mkara/b953cc2585b18ee098cd#file-genesis-md
Then, we can create the database with the following command :
geth --datadir="./ethereumdata" init genesis.json
This command is used everytime you mount a new node. So each node need to have the genesis file. If you want to test on the same machine mounting several nodes, change nodes ipc pipelines and ports .
datadir is the context directory that will store your database as it grows and some stuff like account private keys. By default, it use Roaming appdata user directory on Windows if you don't mention it.
3. Setup bootnode
Bootnode is used to tell for new nodes that will join the blockchain how to find the nearest node to synchronize database. It's like an auto discover tool, think it as a dns server.
Whitout setting bootnode, we can mount the network, but everytime you will mount a new node, you need to access console and add peers manually, which can be fastidious in a big network (especially in a production environment).
Every time you launch a new node, it will have an address in order to communicate, like for example this one :
#Geth console
> admin.nodeInfo
enode://865655f2a55c792aa4749d00bf24431fc4b3f686948a047c1f1f3b2569b368900a462cb1658e288f513ab42a3aef74d14d1ee1bac445678aab954ed4b8a90fd8@[::]:30301
NB : you can note the pattern [protocol]://[name]@[ipaddress][port]
To create bootnode, there is a tool in the Geth suite called bootnode.exe (at least for Windows, check it out with your OS).
We will create firstly the key. the key is simply generating the id of the enode. When you will mount your first node, you will tell him to use this bootnode file, thus the node will always have the same enode id.
bootnode --genkey bootnode.key //Create the bootnode key
Then you can instruct to launch an new node :
bootnode --nodekey bootnode.key
I0216 10:01:19.125600 p2p/discover/udp.go:227] Listening, enode://890b6b5367ef6072455fedbd7a24ebac239d442b18c5ab9d26f58a349dad35ee5783a0dd543e4f454fed22db9772efe28a3ed6f21e75674ef6203e47803da682@[::]:30301
You will see that the enode id is the same as in the key file.
You can then tell to other nodes that you will mount which bootnodes to use :
geth --bootnodes="enode://[id]@[ipaddress]:[port]" ...
4. Mount a node
Every new node that will join your blockchain should init the database and then contains at least these parameters :
geth --datadir="./ethereumdata" --bootnodes="enode://........" --networkid=2000
Adapt parameters to your respective values. you can also add others arguments. Node should connect themselves, and when you are in geth console, you can see which peers are connected with the following command :
>admin.peers
[{
caps: ["eth/61", "eth/62", "eth/63"],
id: "3f8f61999252251808972871bc810505d5b33f7de761c98810584279dce9ecabb0b7da0836978e6074f48e2b787048739c9dc1f734403c8adafc0716d16f4dcd",
name: "Geth/v1.3.5-34b622a2/linux/go1.6",
network: {
localAddress: "192.168.0.105:49356",
remoteAddress: "73.217.192.86:30303"
},
protocols: {
eth: {
difficulty: 10197633442299193000,
head: "8f2c1a08cfc80eff8e2aa601254d6f094e0e801b2e4f0bf2aefffaead93daa41",
version: 63
}
}
}, {
caps: ["eth/61", "eth/62", "eth/63"],
id: "cae433c8f8890998f9a8694fae57e480ae1b65b40de1d0f6e823941c9d7ce1adae10c00772358e543487bf3b77a4ef9a34dd352b5ab085629df898071f42b8c6",
name: "Geth/v1.4.0-unstable/linux/go1.5.1",
network: {
localAddress: "192.168.0.105:49340",
remoteAddress: "122.114.96.120:30303"
},
protocols: {
eth: {
difficulty: 10197633442299193000,
head: "4269eb623e002975e9b097c936d004cdbb6fc4c0527c3ff824d257fc2c472b64",
version: 63
}
}
}]
...
Hope you found this useful, and don't hesitate to share your thoughts.
Apologize for my english :)

✅ @aizawa, I gave you an upvote on your first post! Please give me a follow and I will give you a follow in return!
Please also take a moment to read this post regarding bad behavior on Steemit.
Congratulations @aizawa! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!