Deploy Composer REST Server as Cloud Foundry application in IBM Cloud Platform

Hyperledger project starts have some tools to make the development of blockchain application much easier. Hyperledger Composer provides a web UI to allow the definition of blockchain model easier, with the use of javascript.

There are a lot of tutorials available over the internet, therefore I am not going to repeat here. Hyperledger Composer can generate a bespoke REST API based on a business network. However most of the tutorials on Step Five: Generating a REST server by using command below:


REST API will be generated and expose as http://localhost:3000 and http://localhost:3000/explorer

Typically network admin cards are stored at ~/.composer, this will be difficult when Composer REST Server is being deployed in container or Cloud Foundry application in IBM Cloud platform.

My colleague — Jon have been using Cloudant to store the cards, so that either docker image or Cloud Foundry app can access to card in order to connect to Blockchain network. How to do that, there is quick way to do it.

Before start doing the tutorial, install composer-wallet-cloudant

npm install -g @ampretia/composer-wallet-cloudant

This will make composer-cli to use Cloudant as Composer wallet, we need to tell Composer the URL and credential of Cloudant. You can refer to the example

"composer": {
"wallet": {
"type": "@ampretia/composer-wallet-cloudant",
"options": {
"database": "blockchain-wa",
"username": "xxxxxxxxxxxxxxxxxxxxxxx",
"password": "yyyyyyyyyyyyyyyyyyyyyyy",
"host": "",
"port": 443,
"url": ""

With the JSON above, then we export this JSON as environment properties. In MacOS, it will be below (single quote is needed when doing export in Mac):

export NODE_CONFIG='{"composer":{"wallet":{"type":"@ampretia/composer-wallet-cloudant","options":{"database":"blockchain-wallet","username":"xxxxxxxxxxxxxxxxxxxxxxx","password":"yyyyyyyyyyyyyyyyyyyyyyy","host":"","port":443,"url":""}}}}'

Then you can start to use composer card command to import card into Cloudant directly.

Composer REST Server is distributed as Docker image. Many thank to Simon Stone, he built a Docker image that uses Cloudant as wallet.

Cloud Foundry application in IBM Cloud allows deployment of docker image

cf push composer-rest-server-{UNIQUE_NAME} —docker-image sstone1/composer-rest-server:0.18.1 -c “composer-rest-server -c admin@tutorial-network -n never -w true” -i 1 -m 256M — no-start — no-manifest

Set environment variable for Cloud Foundry application

cf set-env composer-rest-server-{UNIQUE_NAME} NODE_CONFIG '{“composer”:{“wallet”:{“type”:”@ampretia/composer-wallet-cloudant”,”options”:{“database”:”blockchain-wallet”,”username”:”xxxxxxxxxxxxxxxxxxxxxxx”,”password”:”yyyyyyyyyyyyyyyyyyyyyyy”,”host”:””,”port”:443,”url”:”"}}}}’

Start Cloud Foundry application.

cf start composer-rest-server-{UNIQUE_NAME}

Then you will have Composer REST API Server running as Cloud Foundry application in IBM Cloud platform.