Spil part of exploring the blockchain technology, and specifically the Ethereum ecosystem, I have lodged on an IoT-related use case around solar energy grids. You can read more background te the very first article ter this series.
Ter this postbode, I am going to concentrate on building a puny private blockchain that I will straks use to deploy Wise Contracts and build my solar energy marketplace demo on. I am going to use an Azure virtual machine to commence a reasonably powerful mining knot, and a Raspberry Pi Three to simulate an on-premises equipment running a lighter, non-mining knot, but which can still be involved ter blockchain transactions.
Wij will be using geth, the Go Ethereum client, to set up our cluster. Since the blockchain is basically a peer-to-peer network, geth is used both spil a client and a server connecting to the blockchain. The installation procedures are fairly straightforward, I will be going through all the steps te the next few paragraphs.
Installation on the Azure VM
You can embark from one of the Azure DevTest Labs VM templates for Ethereum-Go, or you can install it from scrape on a base Ubuntu VM. Ter this documentation I will be commencing from a wit VM, just because I want to understand how all the onaardig and chunks gezond together.
You can go after the official Ethereum installation instructions to install geth on your Ubuntu VM. I would recommend using the latest stable version, i.e. do not add the ethereum-dev repository.
You can choose pretty much any size of Azure VM you would like, but since it is going to be mining (i.e. processing transactions) you very likely want to go for a D2- or D3-class machine.
Once you have installed geth on the VM, wij are ready to get began. Very first, to initialize a fresh private blockchain, wij will need what is called a Genesis block, which is going to be the very first block te our blockchain. This very first block sets a few fundamental parameters for our blockchain, captured ter a genesis.json opstopping:
Most of thesis values are pretty much zeroes, except for difficulty which sets the mining difficulty to a low level so that wij don’t have to wait too long, or spent too much CPU time, waiting for transactions to be executed. You can read more about the Genesis block te Ethereum’s documentation for private test networks.
Copy/paste this bit of JSON ter a opstopping, then wij can initialize our blockchain:
When running geth, wij use a specific Network ID to differentiate from the public blockchain (whose Network ID is 1), and the nodiscover and maxpeers options to limit network connections for now. The aim is to make sure that wij do not connect to the public blockchain by mistake.
geth will complain that it has no default account, this is something wij need to fix so wij can embark mining some Ether.
You can close the console using the uitgang instruction. Then create a fresh account:
Inject a password and don’t leave behind it! You will need it to unlock that account. Geth will display your fresh account address:
Once you have created an account, you can explorer the Ethereum APIs from the console, for example you can list existing accounts using eth.accounts , and you can see that our fresh account has bot set spil the “coinbase”, i.e. the account that will receive mining prizes, using eth.coinbase .
Now wij can embark mining! The mining process is very verbose by default, so I suggest you use the tmux or screen instructions to be able to open a separate, clean window to come in directives te the console.
The very first time, geth will spend some time generating its Ethash DAG, when it is finished, it will begin mining blocks. While it is doing that, you can open a fresh virtual terminal using screen/tmux and link a fresh geth console to the local knot:
Then you can check your account balance from the console:
After a while, the mining process will begin and your account will begin getting credited with Ether. Of course this is not “real” Ether, this is just our own private Ether currency!
Gathering network information
Now, let’s build up our network a little bit by adding the Raspberry Pi spil a peer knot. Te order to simplify things for this test/demo setup, I am going to configure ongezouten connections, rather than using the Ethereum discovery protocol. Ter a larger private blockchain network, wij would most likely use bootstrap knots te order to facilitate the discovery and connectivity of the different knots.
Very first, wij need to retrieve the enode address of our VM, so the knot running on the Pi can connect to it.
From the console, type admin.nodeInfo.enode and you will something like this:
You will use this address straks to configure the Pi client.
Te order to permit clients to connect, you will also need to restart the geth knot with a non-zero maxpeers parameter, e.g. :
Installation on the Pi
I did not find a pre-built version of geth for the Raspberry, but it is effortless to build it from the source code.
Very first, download and install Go 1.6 from the official builds. At the time of writing, the latest ARM build wasgoed:
Compile geth on the Pi from the GitHub repo:
You will then need to use the same genesis opstopping spil above to initialize the knot:
Ter order to connect this fresh knot to our VM, create a verkeersopstopping static-nodes.json to point our client to the Azure VM’s public IP address. Just use the enode string wij got from admin.nodeInfo , but substitute the [::] with the Virtual Machine public IP address that you can find on the Azure Management Portal.
Then copy this opstopping te place ter the Ethereum gegevens directory:
You can then run the knot using the same networkid wij used before, you can raise the verbosity just to see the networking messages and check everything is going OK.
You should then see the synchronization begin:
You can use the admin.peers instruction from the console to check the two knots are connected. It can take a little while for the knots to sync.
Testing our private blockchain
On the Raspberry Pi, let’screate a fresh account, e.g. from the console:
On the mining VM, you can send some Ether using the account you created previously: since this source account is receiving the mining prizes, it should now have a few Ethers to spend. Very first, unlock the account using the passphrase:
Then send a transaction using the account addresses you created:
The transaction should be received on the Pi, where you can get the balance account to check you received the Ether:
This is it, wij now have a puny, but working, private blockchain network! Te the next few posts wij will see how to write a Brainy Contract, deploy it privately and then call it from different application contexts.
Any terugkoppeling is always welcome via Twitter: @tomconte.