Setup Private Ethereum Blockchain in AWS (Amazon Web Services ) or GCP (Google Cloud Platform)

Sourabhh Sethii
DXSYS
Published in
6 min readJun 24, 2018

Step 1 : Launch At-least Two EC 2 Ubuntu 16 LTS or Launch At-least Two VM instance on GCP.

AWS EC 2 Ubuntu 16 LTS Setup.
Running Machine 1 and Machine 2
Google cloud platform : Ethereum Instances

Step 2: Open the inbound ports 30301–30399 in the security group

Step 3: SSH into the Both Nodes (ie. Machine or instance 1 & Machine or instance 2)

Click on (Open in browser window)

Step 4: On both server Install Geth (ie. Machine or instance 1 & Machine or instance 2)

[1]sudo apt-get install software-properties-common

[2]sudo add-apt-repository -y ppa:ethereum/ethereum

[3]sudo apt-get update

[4]sudo apt-get install ethereum

After installation ensure that both servers have geth properly install by running this commands.

geth –help

Step 5: On both server Install Geth (ie. Machine or instance 1 & Machine or instance 2)

On Node 1, Initialize Genesis Block (0th Block) in genesis.json inside /home/ubuntu/eth-dev/ directory.

[1] cd ~

[2] mkdir eth-dev

[3] cd eth-dev

[4] nano genesis.json

Paste the below line into the nano’s window.

{ “config”: { “chainId”: 88881, “homesteadBlock”: 0, “eip155Block”: 0, “eip158Block”: 0 }, “coinbase” : “0x0000000000000000000000000000000000000000”, “difficulty” : “0x30000”, “extraData” : “”, “gasLimit” : “0x2fefd8”, “nonce” : “0x0000000000000088”, “mixhash” : “0x0000000000000000000000000000000000000000000000000000000000000000”, “parentHash” : “0x0000000000000000000000000000000000000000000000000000000000000000”, “timestamp” : “0x00”, “alloc”: {} }

[5.1] Initialize the chain data with below command:

geth — datadir ~/eth-dev/ init genesis.json

[5.2] Start the Ethereum Machine 1 with the below command

geth — datadir ~/eth-dev/ — networkid 45634 — verbosity 3 — ipcdisable — rpc — port 30301 — rpcport 8545 — rpcaddr <Public DNS address of your Node 1> console 2>> ~/eth-dev/eth.log

e.g

geth — datadir ~/eth-dev/ — networkid 88881 — verbosity 3 — ipcdisable — rpc — port 30301 — rpcport 8545 –rpcaddr 35.237.119.203 console 2 >> ~/eth-dev/eth.log

You would see the logs created by the geth client.

Step 6: On Node 2

Initialize Genesis Block in genesis.json inside /home/ubuntu/eth-dev/ directory.

[1] cd ~

[2] mkdir eth-dev

[3] cd eth-dev

[4] nano genesis.json

Paste the below line into the nano’s window.

{ “config”: { “chainId”: 88881, “homesteadBlock”: 0, “eip155Block”: 0, “eip158Block”: 0 }, “coinbase” : “0x0000000000000000000000000000000000000000”, “difficulty” : “0x30000”, “extraData” : “”, “gasLimit” : “0x2fefd8”, “nonce” : “0x0000000000000088”, “mixhash” : “0x0000000000000000000000000000000000000000000000000000000000000000”, “parentHash” : “0x0000000000000000000000000000000000000000000000000000000000000000”, “timestamp” : “0x00”, “alloc”: {} }

Initialize the chain data with below command:

geth — datadir ~/eth-dev/ init genesis.json

Start the Ethereum Node 2 with the below command

geth — datadir ~/eth-dev/ — networkid 45634 — verbosity 3 — ipcdisable — rpc — port 30302 — rpcport 8546 console 2>> ~/eth-dev/eth.log

Step 7: On Node 2

On Node 1, start the miner using the below command:

miner.start()

If you don’t have any coinbase or primary address to start the mining then you need to create a new account/address which will work as a coinbase.

Enter the below command in the geth console. It will ask for the password. DO NOT LOSE THIS PASSWORD IN ANY CASE.:

personal.newAccount(“Sourabh”)

“0xb68818a0768e50278ca3231fa4ff23a423e3e42d”

Above mentioned (without quote) would be the Coinbase address (if it is the first account). Copy this Coinbase address and keep it safe you would need it multiple times.

Now you can start the mining in node 1. using the below command:

miner.start()

Start Mining Blocks

you can stop the mining using the below command :

miner.stop()

As I have provided low difficulty level in JSON file, If you mine for few seconds or minutes you would get some ether mined in your coinbase account.

Step 7: Connect Machine 2 with Machine 1 in Private Ethereum Blockchain Network

On Machine 2, get the enode address of the node so that we can connect it with node 1.

admin.nodeInfo.enode

“enode://b9d0b548174c70a0ea3175dd86929c855976bb390d58c136f14888a3f266843a2d9e369d6bf270e07285956a46e999c5bfe4f4c09267aeab64def10cb46f842e@35.237.170.52:30303”

[Please use your machine public address] this address is structured as enode://public_key@IP-Address:Port. Here you need to replace [::] with the private IP of the Machine 2.

Step 8: Now go to machine 1 and execute the cmds.

admin.addPeer( “enode://5b81114a01d9a382cfc101f13e177f3a784864d6cd9f33eafd33f9fd838fd8c83004766fa90a3cff8ead55d5847e8cd30a0311186b548a12e348449faebe2cbb@35.237.170.52:30302” )

If above command return “true” after executing above command, then it means you have added the machine 2 as a peer to machine 1.

heck the peers details by running below cmd:

> net.peerCount

1

> admin.peers

[{ caps: [“eth/63”], id: “91233bfe9c817a325ee85c0041bb6db8a6645c9a0e2a6d38fa49e7d3824249c6a32c487cd710980efd5791d05ff06629fe499186132a2e7e9ac7e63502dd683f”, name: “Geth/v1.8.8-stable/linux-amd64/go1.9.4”, network: { inbound: true, localAddress: “10.142.0.2:30303”, remoteAddress: “54.169.122.140:54936”, static: false, trusted: false }, protocols: { eth: “handshake” }}, { caps: [“eth/63”], id: “f2c435410be202a7dd9f20b23eb23d767f51756be23d9d599b468df7680e212ec543430580b7971184652be03d5e38076f86a09cc29f9f6133eb64fcd80a691e”, name: “Geth/v0.0.7-akroma-ccecfba1/linux-amd64/go1.9.2”, network: { inbound: false, localAddress: “10.142.0.2:49690”, remoteAddress: “185.221.152.122:30303”, static: false, trusted: false }, protocols: { eth: “handshake” }}]>

Step 9: Other Geth console Cmds

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(“0xae13d41d66af28380c7af6d825ab557eb271ffff”)
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)

Step 9: Logs for references

sourabhsethi8888@etherum-machine-2:~$ sudo apt-get install software-properties-common

Reading package lists… DoneBuilding dependency tree Reading state information… Donesoftware-properties-common is already the newest version (0.96.20.7).

sourabhsethi8888@etherum-machine-2:~$ sudo add-apt-repository -y ppa:ethereum/ethereum

gpg: keyring `/tmp/tmpyngge5kv/secring.gpg’ createdgpg: keyring `/tmp/tmpyngge5kv/pubring.gpg’ createdgpg: requesting key 923F6CA9 from hkp server keyserver.ubuntu.comgpg: /tmp/tmpyngge5kv/trustdb.gpg: trustdb createdgpg: key 923F6CA9: public key “Launchpad PPA for Ethereum” importedgpg: Total number processed: 1gpg: imported: 1 (RSA: 1)

sourabhsethi8888@etherum-machine-2:~$ sudo apt-get install ethereum

Reading package lists… DoneBuilding dependency tree Reading state information… DoneThe following additional packages will be installed: abigen bootnode evm geth puppeth rlpdump swarm wnodeThe following NEW packages will be installed: abigen bootnode ethereum evm geth puppeth rlpdump swarm wnode0 upgraded, 9 newly installed, 0 to remove and 12 not upgraded.Need to get 22.7 MB of archives.After this operation, 85.8 MB of additional disk space will be used.

> eth.coinbase
“0xb68818a0768e50278ca3231fa4ff23a423e3e42d”

Step 10: Now go to machine 2 and start mining.

On Node 2, you can enable the mining like this below and start the mining.

miner.start()

It would show the error saying that coinbase need to be specified explicitly.

miner.setEtherbase(“0xb68818a0768e50278ca3231fa4ff23a423e3e42d”)

NOTE : Please replace “0xb68818a0768e50278ca3231fa4ff23a423e3e42d” with your own Coinbase address.

To check the balance:

web3.fromWei(web3.eth.getBalance(web3.eth.accounts[0]), ‘ether’)

Right : Machine 1 and Left : Machine 2

Step 9: Use Metamask GUI to connect to network and perform transactions.

Connect to Custom RPC.

Connect to Custom RPC provide your machine url to connect with network.

e.g http://35.237.119.203:8545

Conclusion : I hope this article would help you to setup your own private etherum blockchain.

--

--

Sourabhh Sethii
DXSYS
Editor for

I am an author of Building Digital Experience Platform and I am passionate about emerging technologies. https://sourabhhsethii.com/