Ethereum – Create a private PoA blockchain

Hello Techpate guest,

this tutorial will demonstrate how you can setup a private Proof of Authority(PoA) Ethereum Blockchain on AWS. The public Ethereum Blockchain uses Proof of Work(PoW) which has the disadvantage that it consumes a lot of computing capacity to mine a block. I want to setup the chain on a small AWS instance with only a couple of nodes, because of that it is reasonable to use the PoA mechanism. This tutorial shows you how to setup a chain and how connect to a chain from outside via RPC calls. As soon as we can connect to our chain from outside we will send a transaction.

We following components for this tutorial:
– AWS instance (you can get a free tier instance for one year)
– Geth (Installation for Ubuntu: here )
– Puppeth (included in Geth)
– Metamask (Installation here)

First step is to connect to your AWS Ubuntu instance via ssh. After a successful connection we have to prepare a directory structure for the private chain, at the end of this tutorial you will have a structure like this:

For creating 2 directories for the nodes use following command:

After that you can create new accounts:

For both accounts you will need a password which you should note somewhere, as a result you will get an address which you also should note, for example with this commands:

I think the most important part of the chain is the genesis block. This is the starting point of every chain. To get a genesis block we will use Puppeth. It will guide us through the process of the creation of this important block. In this process you can define points like how long should a new block take or which consensus mechanism should be used. I used following settings for my blockchain:

For the start of the authority nodes you will need the networkId, which you can find in the genesis.json file. Now you can initialize the accounts with the genesis block:

If this step was successful you will see “Successfully wrote genesis state” message in your console. The next step is the start of the bootnode:

The command which I use starts the bootnode as daemon and writes the logs to a file with the name “bootnode-logs.txt”.  To get the address of the ENODE, which we will need for the start of the authority nodes, we have to open the log file. Now we are ready to start the 2 nodes:

This commands will start the nodes as daemon and if you want to check the log files you can use the tail -f <logfile> command. In the commands above we define points like: port, is rpc aktive or not, rpc port, the sync mode, which account address should this node use, the address of the boot node. For us, the most important point is the configuration of rpcaddr With this setting we allow connections from outside to this node.

With all the steps above we setup a private Ethereum blockchain, which is accessible from outside. With this setup we can now try to connect from a local machine to our chain. We have to check if Geth is available on the local machine, if not please check the installation guide from the beginning. If you have Geth installed you can use the attach command to connect to the chain:

If the connection was successful you will see:”Welcome to the Geth JavaScript console!”. From this console you can send your transaction with this command:

In this command we have to define from which address to which address we want to transfer coins and how much. In this example we use the coinbase, which is the actual node we are connected to, which was pre-funded and has enough coins to pay the gas for the transaction. To get a to-address you can use MetaMask to create a new account. Just download and install this plugin and create a new account so you can use the address of this account. But first you have to connect to your chain by typing in the public ip address of your AWS instance and the port which you defined for rpc calls, in my case it is 8502. If the connection from MetaMask to your chain was successful you will see that your MetaMask account got some coins. If you run the sendTransaction command you will get an transactionHash as a result which you can use to get more information about the transaction:

The result will be: in which block is this transaction, sender, receiver, the value, gas etc.

This tutorial showed you how to create a private Ethereum blockchain with help of Geth and Puppeth on a small AWS instance and how to connect to a node and send a first transaction with rpc calls. You got enough to start your own chain and make some transaction. I wish you a lot of fun!!

Leave a Reply

Your email address will not be published. Required fields are marked *