In this article, I shall share solutions of common problems newbies might face when doing some hands-on work with blockchains. For that purpose, we shall use “MultiChain, which is an open source platform for building blockchain applications.
Blockchain as a concept has its own terminologies and functional specifications, and MultiChain follows them, too. With that in mind, you may want to read the following before/while reading further:
Setting Up Your Blockchain Infrastructure
To build a blockchain, a minimum of two nodes are required. If you already have two networked VMs or desktops, then skip this section. Of course, generally, not everyone is so lucky to have this setup. That leads to hours spent building it and then getting distracted.
So, how do we escape from this? Well, the cloud is the solution!
Leverage the AWS Free Tier's services to create two AWS EC2 Instances to simulate a blockchain with two participants.
During that process, it will ask you about your OS. Select the one as per your requirements. I selected “Ubuntu”.
Once the instances are created, AWS will ask you to save a private key to a location of your choice. Keep that location in mind. In order to access your networked Ubuntu VMs, you will need these keys for initiating SSH and SFTP connections.
Use Putty and WinSCP to access your VMs in the cloud.
Producing Your First Ever Block
Log into your first VM and refer to this installation guide to download and install MultiChain.
Once done then, follow the steps below to generate your first block, known as the "Genesis Block."
- Execute the command
multichain-util create InsuranceSettlementChainto create a blockchain named “InsuranceSettlementChain”.
- Use any FTP utility to access <logged-in-user-directory> and you will see a folder named “.multichain”.
- Go inside it and open the “params.dat” file, available in the “InsuranceSettlementChain” directory. You will see a variety of parameters grouped under a specific category. For example, go to the end of the document and you will see the following note:
# The following parameters were generated by multichaind. # They SHOULD NOT BE EDITED.
- Observe that values of all parameters defined in this category are “null”. That’s because our “InsuranceSettlementChain” is created with default values of the parameters, pertaining to the “Genesis Block”, which has yet to be generated. This block shall be generated after executing the multichain server node. We shall see this in the following step.
- The Genesis Block is the first block, on top of which the rest of the blocks shall be generated. To generate this block, execute the command:
multichaind InsuranceSettlementChain -daemon
This command will start the MultiChain server node and generate our Genesis Block.
- Now, reopen the “params.dat” file and go to the end of the document. Observe that those “null” values are overwritten by the runtime values of the Genesis Block.
- Note that once your blockchain is up and running, don’t alter “params.dat”, as it dictates the runtime environment of the blockchain and is referred to by the participating nodes of your blockchain. Its values will be scattered across nodes in your blockchain cluster.
Talking With Your Blockchain, Interactively
MultiChain provides API commands to get information about blockchain node addresses, block hash, wallet-addresses, the list of transactions that happened within your wallet, and so on.
It’s an SQL-like facility provided by MultiChain, and it's proven to be very useful to get insight into your blockchain. You may like to use this facility for the administration of your blockchain security, controlling wallet accessibility, wallet address management, etc.
multichain-cli InsuranceSettlementChain and try the following sample commands to understand your blockchain:
getinfoand notice the attribute “nodeaddress”. This is the address that participating nodes will use in order to connect with our chain, named “InsuranceSettlementChain”.
getaddressesto get a unique hexadecimal address of your blockchain wallet. This wallet will be used to create any digital asset (title certificates, products, asset value in units, etc.) or to transfer that asset from your wallet to another wallet available in the participating node of your blockchain.
getmininginfoto get information about the blocks mined until now and transactions that were part of that block.
There are plenty of other commands that you can use to try to get more details about your blockchain.
In the next article, I will explain how we can scale-out our blockchain by introducing new participating nodes and how integrity of block transactions is ensured through the consensus technique. Until then, cheers…