Reading time: 5 minutes.
Our goal is not focus on Blockchain technology only. We aim to understand what solutions we can build, the impacts in terms of business processes and how can we leverage OutSystems strengths to deliver the benefits faster.
Hyperledger Fabric is a permissioned distributed ledger technology platform, designed for use in enterprise contexts.
As described in the official documentation:
Fabric has a highly modular and configurable architecture, enabling innovation, versatility and optimization for a broad range of industry use cases including banking, finance, insurance, healthcare, human resources, supply chain and even digital music delivery.
Hyperledger Composer aims to simplify developing blockchain solutions making it easier to integrate with the existing business systems.
Prototypes in several industries made the Hyperledger community realize that building blockchain solutions directly on top of Fabric would generate a lot of boilerplate code related to error handling, data validation, access control and remote calls, when the focus should be solving business needs.
Composer allows application developers to build solutions using common development tools with business level concepts like assets, participants and transactions.
This is how those two projects fit in the Hyperledger scope:
In the simplest way I could remember:
- Fabric is the technical framework that will run the blockchain network
- Composer simplifies the development and exposes REST APIs for integration with existing systems
This first post will start with the basics: installation of a development environment for prototyping purposes.
I’ll do a step-by-step tutorial so any person can follow it without troubles.
Let’s dive in. We will:
- Setup a Google Cloud account
- Create an Ubuntu Virtual Machine
- Install Hyperledger pre-requirements
- Install Hyperledger Fabric and Hyperledger Composer
- Deploy a Blockchain Business Network
- Expose the Business Network using a REST API
I will not explain all the concepts behind Hyperledger Fabric and Hyperledger Composer. For that refer to the official documentation.
1. Setup a Google Cloud account
2. Create an Ubuntu Virtual Machine
In the instance creation screen you need to:
- Set the name (“hyperledger-vm” in my case)
- Change the machine type (small is enough to start)
- Select Ubuntu as the operation system and set the storage for 30 Gb
- Check “Allow HTTP traffic”
3. Hyperledger pre-requirements installation
My installation of Hyperledger pre-requirements was based on these instructions with small changes.
For docker-ce execute the following commands (you can copy and paste to the SSH terminal each command using normal CTRL+C / CTRL+V):
sudo apt-get update
sudo apt-get install \ linux-image-extra-$(uname -r) \ linux-image-extra-virtual
sudo apt-get update
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
sudo apt-get update sudo apt-get install docker-ce sudo usermod -a -G docker $USER sudo systemctl enable docker
After these commands you should be able to execute docker:
Next is the installation of docker compose.
sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
If everything is OK, the following command will execute with success and print the docker-compose version.
For Go language all you need to do is:
VERSION=1.9.1 OS=linux ARCH=amd64 sudo curl \ --location https://golang.org/dl/go$VERSION.$OS-$ARCH.tar.gz \ --output go$VERSION.$OS-$ARCH.tar.gz
sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
If everything is OK, the following command will execute with success and print the Go version.
For the node.js installation, I’ll use NVM (Node Version Manager), a simple bash script to manage multiple active node.js versions.
To install NVM, run the following commands:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
For node.js (version 8.X) just run:
nvm install 8
If everything is OK the following should return “v8.11.1” (example).
To finish with the pre-requirements we need to downgrade Python, install the build tools and the unzip utility:
sudo apt-get install python
sudo apt-get install build-essential
sudo apt-get install unzip
4. Hyperledger Fabric and Composer installation
The Hyperleder Fabric and Composer installations are straightforward and the instructions from the documentation work without problems.
For the Fabric the commands are:
mkdir ~/fabric-dev-servers && cd ~/fabric-dev-servers curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.tar.gz tar -xvf fabric-dev-servers.tar.gz
cd ~/fabric-dev-servers ./downloadFabric.sh
For the Composer the commands are:
npm install -g composer-cli
npm install -g composer-rest-server
npm install -g generator-hyperledger-composer
npm install -g yo
npm install -g composer-playground
To start Fabric:
cd ~/fabric-dev-servers ./startFabric.sh ./createPeerAdminCard.sh
To stop Fabric:
To start Composer Playground:
5. Deploy a Blockchain Business Network
For building a blockchain network you have two options:
- Develop one from scratch
- Use one of the samples that Hyperledger Composer can produce
To have something quickly to do some testing, I’ll explain only the second one.
The Composer Playground can connect to blockchain networks running on a Hyperledger Fabric or simulate a network directly in the browser.
This second option comes with a predefined templates that one can use to:
- Export to the file system
- Import to the Fabric
- Generate REST APIs
For the export/import follow the next steps.
First, create a new business network on the Web Browser connection:
Once the network is created, connect to it and use the export option as indicated in the images below. This produces a BNA (Business Network Archive) which is essentially a zip file with all the network elements definition.
The next step is to transfer this file to our Hyperledger VM. Check this link on how to do it. Basically you need to install the Google Cloud command line tools and execute the following commands.
The first one initializes the gcloud with the project settings:
The second one will make the copy using SCP (replace PATH_TO_FILE and GCLOUD_USER with the correct values for you):
gcloud compute scp PATH_TO_FILE\animaltracking-network.bna GCLOUD_USER@hyperledger-vm:animaltracking-network.bna
To install the network execute the following commands:
cp animaltracking-network.bna fabric-dev-servers cd fabric-dev-servers
composer network install --archiveFile animaltracking-network.bna --card PeerAdmin@hlfv1
composer network start --networkName animaltracking-network --networkVersion 0.2.4-deploy.0 --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw
Next, import the generated business card:
composer card import --file email@example.com
6. Generating a REST API
To expose a REST API we need the exploded BNA:
mkdir animaltracking-network mv animaltracking-network.bna animaltracking-network/animaltracking-network.bna.zip cd animaltracking-network unzip animaltracking-network.bna.zip
The result will be similar to:
Archive: animaltracking-network.bna.zip extracting: package.json extracting: README.md extracting: permissions.acl creating: models/ extracting: models/com.hyperledger.composer.animaltracking.cto creating: lib/ extracting: lib/model.cto.js
To start the REST server execute the following command:
composer-rest-server -c admin@animaltracking-network -n never -w true
After this long instructions we have a network deployed and exposed using a REST API.
The next steps will be to connect this network to Business Processes running in OutSystems.