Decentralized networks
System Analysis and Design
Development of mobile applications
Mobile applications design
September 24

Tutorial For Creating Blockchain Solution on Hyperledger Composer



Due to modern business demands, IBM joined hands with other companies to develop an open-source business blockchain network called Hyperledger Fabric project that is touching the sky. Due to modular architecture, digital keys, and on-demand data retrieval, hyperledger fabric is regarded as the base for the world’s future modular architecture blockchain-based apps. Further benefits of Hyperledger Fabric are given below to facilitate your interpretation.

Modular Structure

Hyperledger Fabric makes easier for a developer to create their own pluggable components straight into the blockchain architecture. A developer will be able to introduce new modules whenever they need or desire. And, they don’t need to build the system from the beginning again.

PKC11 Digital Keys

Hyperledger Fabric features modified and unmodified PKC11 for the generation of digital keys. These keys enhance data protection particularly. Think of a mortgage company using blockchain technology. A mortgage is not expected to be exposed publicly. It requires the parties to check themselves in the network to ensure authenticity. With a modular blockchain framework like Hyperledger Fabric, you can provide enough data of security needed in the sensitive data sections.

Data Retrieving When Necessary

Hyperledger Fabric’s channels have not been given the importance they deserve so far. Channels allow for data partitioning that makes it possible to keep the data safe that is supposed to be from a blockchain framework. This is useful where the finance company thinking about to adopt blockchain but competitors seeing the company’s data. With the help of channels on Hyperledger Fabric, you can store sensitive data in data partitions. Traditional/public blockchains are lacking this convenient feature.

Indubitable Trust

Hyperledger Fabric manages transactions differently and efficiently. It lessens the necessary number of trust layers and verifications through which a transaction goes. This makes transactions to go easier, done more quickly, and without any problem on any digital platform.

Hyperledger Fabric is an extensive topic, but for developers who are interested in blockchain application development will find this post helpful.

Here I’m talking about getting started with Hyperledger Composer.

Hyperledger Composer is my favorite tool for blockchain application development. Built on tools including node.js, CLI, npm, and editors, hyperledger composer offers sample apps as well as tools to test the DevOps process to create blockchain applications.

Hyperledger Composer can be installed by running the following script:

cd $HOME
curl -O -k
https://hyperledger.github.io/composer/latest/prereqs-ubuntu.h
chmod u+x prereqs-ubuntu.sh

Run the following command to start the installation process:

sudo apt-get install -y software-properties-common

The installation process requires components ready:

CLI tools

npm install -g composer-cli@0.20


Playground

npm install -g composer-playground@0.20

Hyperledger Fabric

mkdir ~/fabric-dev-servers && cd ~/fabric-dev-servers

IDEs

You can use many IDEs with Hyperledger Composer. The two most common types are Atom and VS Code IDEs.

Atom IDE

Download Atom IDE @ atom.io

Atom is a free and open-source text editor IDE that helps you to write code faster with its feature smart-auto completion. It also supports cross-platform editing, thus, allow Atom to work across different operating systems. You can split codes into multiple panes to compare and edit codes across different files.

Steps to add project folder to Atom:

Go to File Menu.

Click on Add Project menu or press (ALT+CTRL+O).

Specify the path of your folder and select the folder.

Create the ‘File’ by clicking on the ‘New File’ menu option.

This is how a file opened in Atom:



Steps to run an HTML file in Atom:

Right-click on the opened file.

Open the “File” on the web browser.

Open the “Script-Runner” to run scripts inside Atom IDE.

(Note: It supports CoffeeScript, Python, JavaScript, Bash, and Ruby)

VS Code

Download Visual Studio Code IDE @ code.visualstudio.com/download

Visual Studio supports the features of a source code editor with Intellisense code completion, tooling, debugging with breakpoints, call stacks, and an interactive console. The VS code for Hyperledger Composer helps you to become more productive with its syntax highlighting, easy customization, community-contributed keyboard shortcut mappings, box selection, and auto-indentation.

I will walk you through the steps of creating a blockchain solution using Hyperledger Composer.

The following steps will give you an overview of techniques to apply to your own development work:

Hyperledger Composer works for the key concept of business network definition (BND) that helps you create your blockchain solution in the easiest way possible.

Step 1

The first step is to use the Yeoman generator to create the structure of a business network. Use this command to complete the step:

yo hyperledger-composer:businessnetwork

For command execution, you will require the name of the business network, author name, author email address. Simply enter tutorial-network.

Enter — Apache 2.0 as license selection details.

Enter the namespace by following this command;

rg.example.mynetwork

Step 2

The second step is about defining a business network that is made up of:

  • Participants
  • Assets
  • Transactions
  • Access control rules
  • Events and queries

Open the model file

org.example.mynetwork.cto 

Replace the content with following codes:

/**
 * My commodity trading network
 */
namespace org.example.mynetwork
asset Commodity identified by tradingSymbol {
    o String tradingSymbol
    o String description
    o String mainExchange
    o Double quantity
    --> Trader owner
}
participant Trader identified by tradeId {
    o String tradeId
    o String firstName
    o String lastName
}
transaction Trade {
    --> Commodity commodity
    --> Trader newOwner
}

Save all the changes made by you with the following command:

org.example.mynetwork.cto

Steps to Add JavaScript Transaction Logic

The transaction processor function file contains the JavaScript logic that executes the transactions given in the model file.

Step 1

Open the logic.js script file.

Step 2

Replace the whole content by following the code:
/**
 * Track the trade of a commodity from one trader to another
 * @param {org.example.mynetwork.Trade} trade - the trade to be processed
 * @transaction
 */
async function tradeCommodity(trade) {
    trade.commodity.owner = trade.newOwner;
    let assetRegistry = await getAssetRegistry('org.example.mynetwork.Commodity');
    await assetRegistry.update(trade.commodity);
}

Finally, save the changes to

logic.js

Steps to Add Access Control to Your Blockchain Solution:

Step 1
Use this file permissions.acl and replace the control rules by following:

/**
 * Access control rules for tutorial-network
 */
rule Default {
    description: "Allow all participants access to all resources"
    participant: "ANY"
    operation: ALL
    resource: "org.example.mynetwork.*"
    action: ALLOW
}

rule SystemACL {
  description:  "System ACL to permit all access"
  participant: "ANY"
  operation: ALL
  resource: "org.hyperledger.composer.system.**"
  action: ALLOW
}

Step 2
Save the changes made to permissions.acl.

This is how you can define the business network for your blockchain solution.
I will tell you how this business network should be packaged into a deployable business network archive .bna file.

Use the tutorial-network directory and run the following command:
composer archive create -t dir -n

After the correct execution of the command, you will see a business network archive file tutorial-network@0.0.1.bna that has been created in the tutorial network directory.

Steps For the Deployment of Business Network:
Step 1

From the tutorial-network run the followinacg command:

omposer network install --card PeerAdmin@hlfv1 --archiveFile tutorial-network@0.0.1.bna

Step 2

To start your business network use this command:

composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card

Step 3

Import the network administrator identity by following the command:

composer card import --file networkadmin.card

Step 4

To check whether the business network has been deployed successfully or not use the following command:

composer network ping --card admin@tutorial-network

Steps for Generating REST API Server

It is also important to add a layer of language-neutral abstraction to your blockchain solution. REST API can generate that layer to your blockchain app.

Step 1

In the first step you need to create the REST API by navigating to the tutorial-network directory and by running the following command:

composer-rest-server

Step 2

Next, enter the card name by using:

admin@tutorial-network

Step 3

In the next step, use “never use namespaces” when you are asked to use namespaces in the generated REST API.

Step 4

Select the option “No” when asked to secure the API

Step 5

Select the option “Yes” when asked to enable the option of event publication

Step 6

Again select the option “No” when asked to go for TLS Security.

Step 7

You will see the generated API connected to your blockchain business network.

How to Develop Angular 4 Application on Hyperledger Composer?

Step 1

Use tutorial-network directory and run the command:

yo hyperledger-composer:angular

Step 2

Connect the running
business network by pressing “Yes” in the command box.

Step 3

For your business network card enter the command:

admin@tutorial-network

Step 4

Connect to REST API by selecting “Connect to existing REST API” and go further.

Step 5

For the REST server address, select the option localhost and enter 3000 for the server port.

Step 6

Select the option of “namespaces are not used” and go further.

Step 7

Run the application by using npm start.

Step 8

You will have your Angular 4 application ready on REST API that you can check admin@tutorial-network.

By taking the above points into perspective, I can sum up the post on three core points required to create a blockchain solution on Hyperledger Fabric Composer. These points are, fabric blockchain network, deploy blockchain solution to the network, and Fabric REST API server. And developers should always remember the principle of convoluted app designing. And equally important, you need to find a competent and experienced developer that can bring you good results.

Thank you for reading and I welcome your feedback and input.

+5
284 1
Leave a comment