Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Get Started With MultiChain on Windows PC (Part 1)

DZone's Guide to

Get Started With MultiChain on Windows PC (Part 1)

Part 1 of this blockchain experiment involves getting a private blockchain set up on a Windows machine using two nodes to connect and communicate.

· Security Zone ·
Free Resource

Protect your applications against today's increasingly sophisticated threat landscape.

This article is not a guide to teach you blockchain theory. It is a how-to article to get you started with multichain on a single machine.

Ever wanted to get started with blockchain but didn’t know where to start? There are many platforms out there, each having its pros and cons. What will be the steps to follow in order to create your own solution? A good choice to start would be MultiChain – a platform for blockchain based on Bitcoin created by the guys at Coin Sciences Ltd. With MultiChain, you can create your own private blockchain even for enterprise usage, easily configurable and permissioned. It is a platform designed to be easy to get started. They have a great Q&A and, overall, good documentation for their API. 

For Part 1, we will create a private blockchain on our PC and interact with it. Furthermore, I will show you how you can have a second node on the same PC. The two nodes can interact with the blockchain on the same PC, the same way as it would if you had two different PCs on the same network. In a real-world scenario, you would have different computers or VMs or Docker containers, but in this tutorial, we will use one PC without any VM or Docker.

In Part 2, we will create a Java project and interact with the blockchain.

Start by installing MultiChain on your Windows PC.

Along with the extracted .exe files, you will see a README.txt file. Read it, especially the section WINDOWS NOTES, since you are on a Windows PC. 

My extracted folder is: C:\Users\ykarav\Downloads\multichain-windows-1.0.4.

Navigate to yours accordingly. Here, we will create a blockchain with the name tutchain.

Open a cmd on the extracted folder location and run the following command:

multichain-util.exe create tutchain

Image title

You will see a message indicating that the chain was created successfully. Also, you might notice the message about the params.dat file. This file contains parameters that you can change. Parameters regarding permissions, consensus and much more. Please be very careful with these parameters. Read the documentation before you change anything.

Inside this directory, along with the params.dat file, you will also find a multichain.conf file. This file contains your username and password.

Image title

Our private blockchain was just created! Now it is time to connect to it.

Run the following command:

multichaind.exe tutchain -daemon

Image title

Your node will start and you will see the IP and the PORT.

Image title

As you can see, my machine has two available IP/PORTS that other nodes can use to connect to it.

So far, you have a blockchain running on one node, our Windows PC. Since we created the chain, we have the full permissions for it. Let's get some info about the chain and our permissions.

To see the info about our tutchain, open a new cmd at the same location (unfortunately this has to be done since we are on a Windows PC…) and run the following command:

multichain-cli.exe tutchain getinfo

Image title

You will see the following JSON with info about the chain. Also notice the JSON-RPC call highlighted in red. You will need this info later when we run our Java project.

Image title

Try the following command to see your permissions:

multichain-cli.exe tutchain listpermissions

Image title

You will see a full list of your permissions such as: “mine”, “create”, “admin”, “connect”, etc.

So far, you have a blockchain up and running with only one node connected to it – your PC. Let’s create a second node and connect it to our chain.

Remember the first command we used to create the blockchain? The one where it informed us about the params.dat file. See the path to this file. For me, it is the following:

C:\Users\ykarav\AppData\Roaming\MultiChain\tutchain

It means that your chain lies inside: C:\Users\ykarav\AppData\Roaming\MultiChain

Also, take a look at the line where it says: “Other nodes can connect to this node using:” There you can see the IP and PORT that you need to provide to the second node for it to connect to the first one.

We will use a second node on the same PC, so we have to create one. Create a folder with the name MultiChain_Other inside the Roaming folder. You will have something like the following:

C:\Users\ykarav\AppData\Roaming\MultiChain_Other

We will create the new node and start it, but this time, we will use parameters to indicate the path to the second node and also the ports to be used for the connection.

A quick note here. Since our chain already exists every new node will not have full permissions. So node1 have to assign “connect” permission to node2.

Run the following command to create the second node:

multichaind.exe -datadir=C:\Users\ykarav\AppData\Roaming\MultiChain_Other -port=10255 -rpcport=10254 tutchain@172.16.212.153:6753

Image title

As we expected, we cannot yet connect to node1. But as you can see, MultiChain informs us about the connect permissions we need and how to run the command.

Here, 1H5n5Axy2RyVmSWwnUA1qziTrhoqRDexqaLJd8 is the address of the second node. We will provide it with the “connect” permission now from node1.

Run the following command to provide the “connect” permission to node2:

multichain-cli.exe tutchain grant 1H5n5Axy2RyVmSWwnUA1qziTrhoqRDexqaLJd8 connect

Image title

As you can see, we successfully granted connect permissions to node2. Another thing to notice here is that this transaction generated a hash number (30109747….)

Now, node2 can connect to node1. Start node2 again, same as before:

multichaind.exe -datadir=C:\Users\ykarav\AppData\Roaming\MultiChain_Other -port=10255 -rpcport=10254 tutchain@172.16.212.153:6753

Image title

And that’s it! You have a blockchain running on a single machine having two nodes.

Try to run the getinfo command again, but this time, from node2:

multichain-cli.exe -datadir=C:\Users\ykarav\AppData\Roaming\MultiChain_Other -port=10255 -rpcport=10254 tutchain getinfo

Image title

You will see a JSON with info about the blockchain. You can experiment more with API commands from https://www.multichain.com/developers/json-rpc-api/

Let's try the “listaddresses” command. Try the following and see the result on your console:

multichain-cli.exe tutchain listaddresses
multichain-cli.exe tutchain listaddresses * true


We are just scratching the surface here. There is so much more you can do with MultiChain. Worth noticing is the STREAMS feature in MultiChain. You can use it to save and retrieve information.

The MultiChain team has a great section for developers on their site. Start from there!

Rapidly detect security vulnerabilities in your web, mobile and desktop applications with IBM Application Security on Cloud. Register Now

Topics:
blockchain ,multichain ,security ,windows

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}