C 311: Local Multichain (20 pts.)

What you need:

Purpose

Multichain is a very nice, free product that allows you to easily set up blockchains and to customize them. For an excellent explanation of possible business cases for such blockchains, read:

Four genuine blockchain use cases

Installing Multichain (Both Machines)

Do this on both machines.

In a Terminal window, execute these commands:

cd /tmp
wget https://www.multichain.com/download/multichain-latest.tar.gz
tar -xvzf multichain-latest.tar.gz
cd multichain-1.0.8
sudo mv multichaind multichain-cli multichain-util /usr/local/bin

Creating a Blockchain (Primary Node)

Do this on the Primary Node:
multichain-util create chain1
multichaind chain1 -daemon
The response contains the command to use to join the blockchain, as highlighted in the image below.

Joining a Blockchain (Secondary Node)

On the Secondary Node, execute the command to join the blockchain, like this:
multichaind chain1@10.138.0.3:6759
The node can't join the blockchain, because it lacks "connect" permission.

The command that must be executed on the Primary Node is shown, as highlighted in the image below.

Granting Permission (Primary Node)

On the Primary Node, execute the command shown on the Secondary Node, as shown below:
multichain-cli chain1 grant 1RnzED3U3fgmiBQqdriweSSs6Sh71zW6irTs4i connect
The command succeeds, returning a long Transaction ID number, as shown below.

Joining a Blockchain (Secondary Node)

On the Secondary Node, execute the command to join the blockchain, appending "-daemon" to it, like this:
multichaind chain1@10.138.0.3:6759 -daemon
The node joins the blockchain successfully this time, as shown below.

Using multichain-cli (Either Node)

On either node, execute this command:
multichain-cli chain1 help
A long list of commands appears, including the "getinfo" command, as shown below.

On either node, execute this command:

multichain-cli chain1 getinfo
Information about the blockchain appears, as shown below. Notice that the blockchain is very small, containing only 48 blocks. Multichain doesn't mine blocks when there are no new transactions, making it far more efficient for small, closed blockchains than Bitcoin or Ethereum.

On either node, execute this command:

multichain-cli chain1 help getinfo
The help message explains how the "getinfo" command works, and ends with examples, including one starting with "curl", as highlighted in the image below.

The "curl" commands show how to use the RPC, which is designed for Web-based clients and GUI's.


C 311.1: Blockchain Status (10 pts)

On either node, execute this command:
multichain-cli chain1 getchaintips
The flag is the "status" of your blockchain, covered by a green box in the image below.


Installing Apache and PHP (Both Nodes)

On both servers, execute these commands, one at a time, to install Apache and PHP 7.3:
sudo apt update
sudo apt install git curl apache2 -y
sudo apt install ca-certificates apt-transport-https lsb-release -y
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.3.list
sudo apt update
sudo apt install php7.3 php7.3-cli php7.3-common php7.3-opcache php7.3-curl php7.3-mbstring php7.3-mysql php7.3-zip php7.3-xml php7.3-dev -y

Installing the GUI (Both Nodes)

Execute these commands:
cd /var/www/html
sudo git clone https://github.com/MultiChain/multichain-web-demo.git
cd multichain-web-demo/
sudo cp config-example.txt config.txt

Finding the RPC Credentials (Both Nodes)

Multichain randomly chooses credentials when you create a blockchain. To see them, execute these commands:
cat ~/.multichain/chain1/multichain.conf
grep rpc-port ~/.multichain/chain1/params.dat
You see the username, password, and port number, as shown below.

Now you need to enter those credentials into the GUI configufation file.

Execute this command:

sudo nano config.txt
Enter the port and password into this file, as shown below.

To save the file, press Ctrl+X, Y, Enter.

Execute this command to restart Apache:

sudo service apache2 restart

Troubleshooting

If you have a Multichain node running and you want to delete it and start over, execute these commands:
pkill multichain
cd
sudo rm -r .multichain
sudo rm -r /var/www/html/multichain-web-demo

Troubleshooting

If you are developing more PHP pages, it helps to turn on PHP error reporting. This is insecure, and should not be enabled on production servers.

To find the PHP configuration file, execute these commands:

sudo updatedb
locate php.ini
Find the file in an "apache2" folder, as highlighted in the image below.

Execute this command to edit that file, adjusting the file path as necessary:

sudo nano /etc/php/7.2/apache2/php.ini
Change display_errors to On, as shown in the image below.

Save the file with Ctrl+X, Y, Enter.

Execute this command to restart Apache:

sudo service apache2 restart

Allowing HTTP Traffic (Both Nodes)

In the Google Cloud Platform page, in the line for one of your Debian servers, on the right side, click the three-dot icon, and click "View network details", as shown below.

On the "Firewall rules" page, click "CREATE FIREWALL RULE", as shown below.

On the 'Create a firewall fule" page, make these entries, as shown below:

At the bottom of the page, click the Create button.

Using the GUI (Both Nodes)

In the Google Cloud Platform page, on the top left, click the three-bar "hamburger" icon.

Click "Compute engine", "VM instances".

Find the "External IP" of your instance, as shown below.

In a Web browser, enter the "External IP" address followed by /multichain-web-demo.

The GUI opens, as shown below. Click Default.

You see basic information about your blockchain, as shown below.

Primary Node

Examine the GUI for your Primary Node.

Notice on the right side that the Primary Node has many Permissions, including "send", "receive", "create", and "admin".

Troubleshooting

Here are some common problems and solutions.

Multichain Not Running

Problem: "Error: HTTP 0", as shown below.

Solution: on the primary node, execute this command:

multichaind chain1 -daemon
Solution: on a secondary node, execute this command, adjusting the IP and port number as needed.
multichaind chain1@172.16.1.253:6457 -daemon

Incorrect RPC Password

Problem: "Error 401 Unauthorized", as shown below.

Solution: execute this command to find the correct password:

cat ~/.multichain/chain1/multichain.conf
Execute this command to correct it:
sudo nano /var/www/html/multichain-web-demo/config.txt

Secondary Node

The Secondary Node has only "connect" permission.

Issuing An Asset

In the Primary Node's GUI, in the top menu bar, click "Issue Asset".

Fill in these fields, leaving the other fields at their default values, and replacing "YOURNAME" with your own name, as shown below.

Scroll to the bottom of the page and click the "Issue Asset" button.

A green message says "Asset successfully issued...", as shown below.

Sending Coins to the Secondary Node

In the Primary Node's GUI, in the top menu bar, click Send.

On the right side, in the "Send Asset" section, click the "To address" field. Only one address is available, as shown below, and it's "local" -- that is, the Primary Node itself.

We can't send assets to the Secondary Node, because it doesn't have receive permission.

Granting Permissions to the Secondary Node

In the Primary Node's GUI, in the top menu bar, click Permissions.

On the right side, in the "Change Permissions" section, the "For address" is empty, as shown below.

In the Secondary Node's GUI, at the top right, in the "My Addresses" section, highlight the address, right-click, and click Copy, as shown below.

In the Primary Node's GUI, in the right side, in the "Change Permissions" section, paste the address into the "For address" field.

Check Send and Receive, as shown below.

Click the "Change Permissions" button. A green message says "Permissions successfully changed...".

Sending Coins to the Secondary Node

In the Primary Node's GUI, in the top menu bar, click Send.

On the right side, in the "Send Asset" section, click the "To address" field and select the second address, the one that is not "local".

Enter a Quantity of 50, as shown below.

Click the "Send Asset" button.

A green message says "Asset successfully sent...".

In the Secondary Node's GUI, in the top menu bar, click Send.

On the left side, the "Available Balances" section now shows 50 "YOURNAME-Coin", as shown below.

Issuing Another Asset

In the Primary Node's GUI, in the top menu bar, click "Issue Asset".

Fill in these fields, leaving the other fields at their default values, and replacing "YOURNAME" with your own name, as shown below.

Scroll to the bottom of the page and click the "Issue Asset" button.

A green message says "Asset successfully issued...".

Preparing an Atomic Exchange Transaction

This is one of the most important features of Multichain: the ability to exchange one asset for another in a single "atomic" transaction, to avoid errors in which payment is sent but goods are not received.

In the Primary Node's GUI, in the top menu bar, click "Create Offer".

On the right side, in the "Create Offer" section, enter these values:

Click the "Create Offer" button.

A green message says "Offer successfully prepared...", as shown below.

On the left side, in the "Available Balances" section, one YOURNAME-GoldCoin is now "locked" -- that is, it cannot be spent for any other purpose, to ensure that it remains available for the atomic exchange.

Under the green message a long line of hexadecimal text appears, as highlighted in the image below. Double-click it and copy it to the Clipboard.

Performing the Exchange

In the Secondary Node's GUI, in the top menu bar, click Accept.

On the right side, in the "Decode Offer" field, paste in the hexadecimal text, as shown below.

Click the "Decode Offer" button.

The "Complete Offer" section appears, as shown below, showing that we can get a YOURNAME-GoldCoin for ten YOURNAME-Coins.

Click the "Complete Offer" button.

The exchange is successful, and you now have a GoldCoin, as shown below.


C 311.2: Viewing the Secondary Node (10 pts)

In the Secondary Node's GUI, in the top menu bar, click Node.

On the right side, in the "Permissions" line, find the word that is redacted in the image below. That's the flag.

Sources

Installing MultiChain
How to Install PHP 7.3 on Debian 9
Posted 6-4-16 by Sam Bowne
Revised 6-11-17
Updated to 1.0.1 10-16-17
Changed to a Windows project 6-15-18
GUI Troubleshooting images added 7-20-18
Moved to Google Cloud and new scoring engine 7-7-19