Building Blockchain network with Hyperledger Fabric and Composer

10 May, 2019 | 3 minutes read

In one sentence, Blockchain is a trusted distributed ledger that records transactions that occur in the network. Why do we need it?

Blockchain technology revolutionized the traditional business networks and replaced the old inefficient, expensive and vulnerable systems.

In my previous blogpost, I explained how to build smart contracts for the Ethereum Blockchain. Now, I will give a brief overview how to do it using Hyperledger fabric and composer.

Hyperledger Fabric is a permissioned network that provides framework for Blockchain applications. Unlike other Blockchain implementations, it satisfies all four elements of Blockchain for business. It is a permissioned network, the transactions are confidential, it does not rely on cryptocurrency and it is programmable.

Hyperledger composer is a web-based interface that simplifies the modeling and the testing of the network. Composer enables us to deploy an archive of the business network on the fabric network. This archive consists of three required files:

  • the network model – which defines the resources
  • script file – that defines the business rules
  • access control file- that contains rules for different participants on the resources of the network.
Building Blockchain network with Hyperledger Fabric and Composer

In this application I will set up one hotel payment processed by REST API server, that will allow client-side software to interact with the business network.

After the installation of composer tools and Hyperledger Fabric Runtime, we generate peerAdmin card. The owner of the card has the privilege of managing the business network on the fabric.

Creating business network with Yo-generator

Building Blockchain network with Hyperledger Fabric and Composer

Yo is used to set up a sample business network. Besides that, generator-hyperledger-composer can generate model, loopback or Angular application.

To model the network, we should open the Model file and define the network resources and transactions in them.  Then, we write the logic of the transaction in the script file and define the rules in the permissions file.

After the coding is finished, we should:

-Create the archive
composer archive create  –sourceType dir –sourceName ../

-Install the BNA
composer network install -a hotel@0.0.1.bna -c PeerAdmin@hlfv1

-Start the BNA
composer network start -c PeerAdmin@hlfv1 -n hotel -V 0.0.1 -A admin -S adminpw

-Import the card that was generated
composer card delete -c admin@hotel

Testing the business network

Now, when our network is up and running and we have an archive of it, we can upload it to the Composer playground and test it there.

Navigate to https:// http://composer-playground.mybluemix.net/, select deploy new business network and upload the archive file.


Building Blockchain network with Hyperledger Fabric and Composer

We define our assets. First, we create the participants- our account holders. Guest account holder and hotel account holder.


Building Blockchain network with Hyperledger Fabric and Composer

Then we define the assets- their accounts. Guest account with budget 15000 and hotel account with  budget 50000.


Building Blockchain network with Hyperledger Fabric and Composer

Then we submit the transaction. We define the account that pays and the account that receives the money and the amount of payment, 1000.


Building Blockchain network with Hyperledger Fabric and Composer

After the transaction is submitted, we can see the new state in the assets window.


Building Blockchain network with Hyperledger Fabric and Composer

The hotel’s account now has 51000 and guest’s account has 14000, which means the transaction was successful.

Generate Rest Service

Another way to interact with the business network is with Rest Server. Type composer-rest-server in your terminal and specify admin@hotel.card, select never use namespace and continue with the default settings.


Building Blockchain network with Hyperledger Fabric and Composer

Follow the link and you are navigated to the rest server where you can play with the network components similarly like in the composer playground.

Conclusion

The purpose of Hyperledger is to provide an environment for facilitating commercial adaptation of Blockchain and easy-to-use API-s that enable simple development and interoperability.

Although new and challenging, the concepts are simple, modular, and easy to grasp for IT and business professionals.

If your business network needs managing of relationships, transaction tracking, unbiased control, and increased transparency or your system is prone to errors due to manual processes, Hyperledger Blockchain can make a huge difference for you!