Create your first permission blockchain solution with Multichain
By: Shams Nahid
Tags: Nodejs, Getting Started, Multichain, Blockchain, Expressjs

Getting started with Multichain platform

Multichain

Multichain is an open-source, bitcoin forked permission blockchain solution.

Scenario

Let’s Imagine an application that is shared by multiple organizations. The application is interacting with an underlying database.

In a traditional centralized architecture, this database is hosted and administered by a single party which all of the participants trust, even if they do not trust each other.

Transactions which modify the database are initiated only by applications on this central party’s systems, often in response to messages received from the participants. The database simply does what it’s told because the application is implicitly trusted to only send it transactions that make sense.

Multichain provide an alternative way of managing a shared database, without a trusted intermediary [Reference].

While Using Multichain As A Solution

Core advantages are:

Rather than public blockchain, like Ethereum or bitcoin, the transactions and activities are kept private to the selected participants.

Admin/Admins can make sure, which participants can connect to the blockchain and even read or write on the platform.

With all these goodies, although PoW is optional here, we can also include wallets, assets and create our own currency.

Article Objectives

In this article, using multichain, we will create a permission blockchain solution.

Create two nodes

Each node will have a copy of the chain

We tweak some permission between these nodes

Create a block data in the first node chain and Make sure, that block data is available in the sibling node chain

Prerequisites

Two ubuntu instances (AWS EC2 is used here)

Lets Start

Before we start, please create 2 ubuntu instances under the same network. Let’s call the first one origin_node and the second one sibling_1 node.

origin_node is the Genesis node. It also plays the role of admin_node .

The sibling_1 will get permission to connect with the chain and write.

For creating an instance, please consider the following criteria

Use ubuntu 16.04 server

Use a security group that allows port 443 , 22 and 8333

443 for HTTPS, 22 for SSH and 8333 for Custom TCP

Prepare origin_node

The objective of this section is to create a genesis node and run the chain. SSH to your origin_node .

ssh ubuntu@origin_node_public_ip -i key

Become a root user

sudo su

Download multichain

Extract files:

tar -xvzf multichain-2.0-alpha-5.tar.gz

Move files to binary directory

cd multichain-2.0-alpha-5

mv multichaind multichain-cli multichain-util /usr/local/bin

Return to home directory

cd ~

Create a genesis node

multichain-util create my-blockchain

Update default network and RPC port to 8333 and 8332

nano /root/.multichain/my-blockchain/params.dat

You can use the default network port . But you have to ensure to put the port explicitly in the next command.

Now run the node,

multichaind my-blockchain -daemon

You will get response like,

Other nodes can connect to this node using:

multichaind my-blockchain@origin_node_ip:8333

Now configure HTTPS and default network port firewall.

HTTPS for syncing and interacting other nodes and default network port to connect with other nodes.

ufw allow OpenSSH

ufw allow in 443/tcp

ufw allow in 8333/tcp

ufw enable

ufw status

We successfully run a multichain node.

Prepare a sibling_node:

Just like the previous origin_node install multichain.

ssh ubuntu@origin_node_public_ip -i key

sudo su

wget https://www.multichain.com/download/multichain-2.0-alpha-5.tar.gz

tar -xvzf multichain-2.0-alpha-5.tar.gz

cd multichain-2.0-alpha-5

mv multichaind multichain-cli multichain-util /usr/local/bin

cd ~

Initialize chain from origin_node

multichaind my-blockchain@private_ip_of_origin_node:8333

Now you should get a wallet address for further transactions.

Great, one sibling node is initialized.

Right now it’s the chain is initialized. But it does not have any permission to connect or write to the chain.

Grant Permission from origin_node :

We will grant Permission of sibling_node to connect and write to the chain.

From the origin_node , grant permission to connect and write,

multichain-cli my-blockchain grant sibling_1_node_wallet_address connect,send,receive,mine,create

Since permission is granted, now we can connect and write data to the chain from sibling_1 node.

Write Some Data From sibling_Node

Go to your sibling_1 and connect to the chain,

multichaind my-blockchain -daemon

To write some json data, go to interactive mode,

multichain-cli my-blockchain

Create a stream to mine some block,

create stream my-blockchain-stream true

Write data through the stream

publish my-blockchain-stream "json" '{"json":{"myKey":"myValue"}}'

Make sure, there is no space between the colon , cottation or brackets

It’s time to check, the chain is synced among all the nodes.

Verify Chain Data in origin_node

Now the chain data should be synced through all the nodes. To check this, Go to the origin_node and check if the data block exists in the chain. In the origin_node , Go to interactive mode,

multichain-cli my-blockchain

Subscribe to the stream

subscribe my-blockchain-stream true

Now your data should be displayed

liststreamitems my-blockchain-stream

You will get output something like this,

[

{

"publishers": ["1aokp3bti15AuRs51wPemtBuiqAdRDFaGYnRQw"],

"keys": ["json"],

"offchain": false,

"available": true,

"data": {

"json": {

"myKey": "myValue"

}

},

"confirmations": 4,

"blocktime": 1571709550,

"txid": "transaction_id"

}

]

Next Challange:

Create a 2nd sibling with reading permission and read chain

Create a 3rd sibling with write permission and verify the chain

Integrate an express server

References: