Reputation: 5
I want to build a private blockchain network and I read somewhere that Hyperledger is best suited for private blockchain networks. But I already know about Solidity and hence I want to use Ethereum. So can anyone please answer me if I can build a fully fledged private blockchain network on Ehtereum or do I have to go into Hyperledger? If there are some steps involved for that, please do tell that also. Thanks in advance.
Upvotes: 0
Views: 276
Reputation: 2706
You sure can. If you're looking for a simple and quick way to bootstrap a private Ethereum network, I would suggest looking at a cloud template solution such as Microsoft Azure's Ethereum Proof of Authority Consortium.
Upvotes: 0
Reputation: 779
Yes you can build private ethereum network. Below i have shown the steps for 2 Node ethereum private network.
Here are the following Steps
Step 0:
Install and setup geth (i.e., ensure its added to the path environment variable)
Step 1:
You need to create the genesis file that will contain information about difficulty, gas limit etc., A sample of the genesis file (genesis.json) is given below
{
"config": {
"chainId": 2018,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x400",
"extraData" : "",
"gasLimit" : "0x2fefd8",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
Step 2:
Setup your node with the following command
geth --datadir data1 (or ./path/to/data/directory give the location where you want to store the data) init genesis.json
Step 3:
Now that we have setup the node from Step 2, let's start the node with the below command
geth --datadir data1 (path to the data directory you have given in **Step 2**) --nodiscover --networkid 123456 (give something that is unique and not either of 0,1, 2 or 3 as these are already predefined networks in ethereum) console
It's very important you have the flag --nodiscover, so that the node is not open for public.
**Step 4: **
If you want to know about your node details (by now with Step 3 command you should have entered into the ethereum node shell) give this command and you will get all the details of the node you just setup.
$ admin.nodeInfo
Step 5:
$ personal.newAccount() // This will create a new ethereum account, but will be locked by default. Ensure the password you have given as this required when sending transactions from this account.
Let's setup another node (Node 2) and connect to the Node 1.
**Step 6: **
Note: We are going to use the same machine for both node 1 and node 2 in our case.
Let's start geth in node 2 with the below command
$ geth --datadir data2 init genesis.json
Step 7:
Let's start the node that we setup in the Step 6 with the following command
$ geth --datadir blkchain2 --nodiscover --networkid 1234 --port 60606 console
Note: We have to specify the port here as a default port has already been occupied by the node 1.
Step 8:
With Step 7 you should be in the ethereum node console. Run the following command to know the node 2 details that has just started running.
> admin.nodeInfo
Step 9:
Let's create a new account in Node 2 with the following command
> personal.newAccount()
Step 10:
Let's connect both the nodes now.
When we ran the command admin.nodeInfo in both node1 and node2 earlier we see a key with the name enode which is of the following format.
enode://ENODE@IP:PORT
If you want to know how enode is created check this awesome response by benjamin
Copy both those enode addresses and run the following command on both node 1 and node 2 consoles respectively.
> admin.addPeer("enode of node1"); // run in console of node 1
> admin.addPeer("enode of node2"); // run in console of node 2
Now, both the nodes are part of the private network and you can interact with one another.
Step 11:
As a verification let's mine on Node 1 and see its reflecting on Node 2.
Go to the console of node 1 and run the following command
> miner.start(1)
The above command will give lot of verbose, in that one important field you should observe is the blockheight (or block number).
Now, go to Node 2 and run the following command to see that the block that was mined is now showing in Node 2.
eth.getBlockNumber
You should now see that the block that was mined in Node 1 is successfully propagated to Node 2.
So, here we end for now.
Any questions feel free to ask me.
PS 1: With different versions of web3 that you are using some commands may vary, but on the high level things should remain mostly the same.
PS 2: If you want to connect a Node 1 running in machine 1 and Node 2 running in machine 2, you just need to run the same. But maybe you need to properly verify the enode of Node 1. Also, you might need to tweak your firewall to allow the bi-directional transactional flows.
Upvotes: 2