Hyperledger Composer Playground

Updated . Posted . Visible to the public.

Playground is an environment that lets you quickly build and test blockchain business networks. It doesn't need a running blockchain network, and so it reduces the complexity of getting a business network defined, validated, and tested.

Interactive Mode

This starts Docker interactively. I like to run Playground like this so I can see what gets logged to STDOUT.

In WSL Ubuntu terminal:

docker run --name composer-playground --publish 8080:8080 hyperledger/composer-playground

where

  • docker run runs the docker image
  • --name composer-playground assigns the name composer-playground to the container
  • --publish 8080:8080 publishes the port 8080 in the container, and port 8080 in the host machine
  • hyperledger/composer-playground is the name of the docker image to run

Exit Playground

When you're finished running Playground, ctrl+c to kill the container in interactive mode.

Detached Mode

If you want to run Playground detached, just add --detach:

docker run --name composer-playground --publish 8080:8080 --detach hyperledger/composer-playground

Exit Playground

To exit Playground:

$ docker stop composer-playground

Connect Playground in Browser

http://localhost:8080

Alternatively, replace localhost with the machine's IP address.

Start Playground After Existing (Interactive or Detached Modes)

$ docker start composer-playground

Issue the above command for the following error:

$ docker run --name composer-playground --publish 8080:8080 --detach hyperledger/composer-playground
docker: Error response from daemon: Conflict. The container name "/composer-playground" is already in use by container "78a527bb1d8bf0fcc74755f59d4de64b730b5158562c00c1b3ad58376af235cf". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.

Remove Playground from Docker

When we are done with Playground and wants to remove its Docker's image:

$ docker rm --force composer-playground

Error: failed to start containers: composer-playground

Error response from daemon: driver failed programming external connectivity on endpoint composer-playground (030cc8e8b89df5e79fd0206ee55f5f4afeb4cd2260246c4ae9b16a2d50946606): Error starting userland proxy: mkdir /port/tcp:0.0.0.0:8080:tcp:172.17.0.2:8080: input/output error
Error: failed to start containers: composer-playground

This is a known issue for Docker version 18.06.1-ce running in Windows 10. To fix, try:

  1. Restart docker using the whale icon in the taskbar.
  2. Wait a couple of minutes for it to be started, then in Ubuntu terminal: kiatng@win10:~$ docker start composer-playground

Testing Playground with Hello World

Steps in browser (http://localhost:8080):

  1. Let's Blockchain
  2. Deploy a New Business Network
    1. Give your new Business Network a name: test-network
    2. Model Network Starter Template: empty-business-network
    3. Click Deploy
  3. Click Connect now
  4. Under Define tab
    1. Edit model.cto
    2. Add script file script.js
  5. Click Deploy changes
  6. Under Test tab
    1. Create New Asset:
      1. testId: 1234
      2. message: 'my first playground'
    2. Click Create New
    3. Click Submit Transaction
    4. Edit test: ...Test#1234
    5. Click Submit
  7. Press F12 to bring up the console, the last entry is Hello: my first playground

Summary of what we do in Playground:

  1. Model Asset and Transaction
  2. Instantiate Asset and pass it to the Asset Registry
  3. Submit transaction and test the Business Network

To start over playground:

  1. Press F12 to bring up the developer panel
  2. Under Storage Tab
  3. Delete cookies, indexed db, local storage
  4. Press F5 to refresh

model.cto

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace org.example.myfirstmodel

asset Test identified by testId {
  o String testId
  o String message
}

transaction Hello {
  --> Test test
}

script.js

/**
 * New script file
 */

/**
 * @param {org.example.myfirstmodel.Hello} hello
 * @transaction
 */
function hello(hello) {
  console.log("Hello: " + hello.test.message);
}

Online Playground at IBM Cloud

There is no need to install Playground locally, we can use Playground in the cloud:

https://composer-playground.mybluemix.net/

kiatng
Last edit
kiatng
Posted by kiatng to Fabric (2018-10-26 01:33)