installing-hyperledger-composer-playground.png

Installing Hyperledger Composer Playground

14/December/2017
    The evolving blockchain environment has brought a lot of blockchain development and testing tools. Building and running custom blockchains is now easier than before. Hyperledger Composer Playground is such a tool which provides an environment that quickly models and tests a blockchain network. The composer has a simple Graphical UI to edit and test the business blockchain network. The playground makes the highly complex blockchain network easy for running. 

    Both online and offline version of Playground is available. While the online playground runs the business network in browser memory, local playground is deployed in Hyperledger Fabric instances.

The Online Playground can be accessed here: https://composer-playground.mybluemix.net

When Playground is used in Browser only mode, all the data including the assets, business networks, transactions, and participants have stored in browser local storage. 
Let's check, How to install hyperledger Composer Playground locally,

Basic needs
  1. Operating Systems: Ubuntu Linux 16.04 LTS ( 64-bit), or Mac OS 10.12
  2. At least 4Gb of memory.
  3. Docker Engine 17.03 or greater
  4. Docker Compose 1.8 or greater

Docker and Docker compose installation in Ubuntu 16.04 LTS (64-bit)
Follow the comments

- install docker
         		$ sudo apt install docker.io
  - install docker compose
         		$ sudo apt install docker-compose
- create a user group
         		$ sudo usermod -a -G docker $USER
You can check the version of docker and docker compose version by
         		$ docker --version
          $ docker-compose --version

If you have used Hyperledger Fabric or Hyperledger Composer Playground locally before, and wish to clear all traces and start fresh, use the following commands. It will delete all downloaded images and any running containers.  But be careful if you are using any other docker images on your machine.

	docker ps -aq | xargs docker rm -f
docker images -aq | xargs docker rmi -f

Creating the containers and installing playground locally

	curl -sSL https://hyperledger.github.io/composer/install-hlfv1.sh | bash
Or 
	docker run --name composer-playground --publish 8080:8080 hyperledger/composer-playground

This command will download and start a Hyperledger Fabric instance and Hyperledger Composer Playground. Before executing this command, make sure the connectivity of the internet. A stable net connection is needed.

If you already install it then use the following command to restart the playground
  -Open terminal
- Type this command and press enter: ./composer.sh

A playground is running now, you can access the playground in a web browser.
Let’s check  https://localhost:8080/login

You can see the Blockchain playground welcome screen.

installing-hyperledger-composer-playground-1-blockchainexpert

Click on the Button “Let’s Blockchain!” to start playground.

installing-hyperledger-composer-playground-2-blockchainexpert

click on the “Deploy a new business network” button. 

installing-hyperledger-composer-playground-3-blockchainexpert

Give a name for the network. 

installing-hyperledger-composer-playground-4-blockchainexpert

We can choose a right template from here. There are several templates will be loaded.
In this example, we have just created an empty-business network template. 
Click the Deploy button to deploy the blockchain. You can see that an ID card for the admin user is also created. 

installing-hyperledger-composer-playground-5-blockchainexpert

In the bottom of the id card, there is a “Connect now” button to connect the admin to the new network, 
You will be directed to define the tab after connected to the business network mode. 

installing-hyperledger-composer-playground-6-blockchainexpert

On the top, we can see a “define” tab and test tab. 
From the define tab, we can define or write and work with the model in the business network.

Click the Add a file button to add a file 

From the wizard, you can add the four necessary files namely 
   - Model file
  - Job script file
  - Query file 
  - Access Control files

installing-hyperledger-composer-playground-7-blockchainexpert

Model file
  In this file, we define the Assets, Participants, and Transactions in the business model.
  Choose this file and click the “Add” button.  The new model file opens automatically.

installing-hyperledger-composer-playground-8-blockchainexpert

/**
 * New model file
 */
namespace org.acme.myfirstmodel
asset Test identified by testId {
  o String testId
  o String message
}
transaction helloworld {
  --> Test test
}
Script File (.js)

/**
 * New script file
 */
/**
 @param {org.acme.myfirstmodel.helloworld} helloworld
 @transaction
 */
function helloworld(helloworld) {
  console.log("Hello world" + helloworld.test.message);
}
Update it by clicking the update button. And we are just ready to test the model.

installing-hyperledger-composer-playground-9-blockchainexpert

Before we can use the test model, we have to instantiate an Asset and store it in the Asset Register.
Create a new Asset, give a testId and message and save it. 

installing-hyperledger-composer-playground-10-blockchainexpert

The instance is saved in the Asset registry.

installing-hyperledger-composer-playground-11-blockchainexpert

Now we can open the javascript console by clicking F12.
Then click on the “Submit Transaction” button for invoking the ‘helloworld’ transaction.

installing-hyperledger-composer-playground-12-blockchainexpert

Then specify the id of the transactions and submit it. We can check the console to see the transaction status. 

installing-hyperledger-composer-playground-13-blockchainexpert

Nothing fancy here, it simply shows you a model for asset and transaction management.
How to instantiate an asset, store the asset in the asset register, and pass the asset into a transaction. 
Obviously, a real application will be more complicated. But I hope it will give you a basic idea to test your model and playground.