DAML on Hyperledger Fabric

Reading Time: 6 minutes

In our last blog, DAML on Hyperledger Sawtooth, we deployed our DAML application on a single node Hyperledger Sawtooth ecosystem, a blockchain platform which is part of the Hyperledger project by the Linux Foundation. We also learned about Sextant for DAML which is a blockchain management platform and combines DAML with the enterprise-grade Hyperledger Sawtooth.

In this blog, we will continue moving forward in our DAML journey and deploy our application on another blockchain platform which is Hyperledger Fabric. 

Let’s get started by getting to know Hyperledger Fabric.

Hyperledger Fabric

Hyperledger Fabric is one of the distributed ledger frameworks under the Hyperledger project. It is a framework for permissioned networks, where all participants have known identities. 

Hyperledger is an open-source community focused on developing a suite of stable frameworks, tools, and libraries for enterprise-grade blockchain deployments. 

Now if you are new to the blockchain world you may think what do we mean by enterprise-grade blockchain and how Hyperledger fabric can be considered an enterprise blockchain. 

So just to make things easy, enterprise blockchain platforms are the platforms that can be used by businesses who want to use blockchain technology to grow their business. To make it more simple, the difference between enterprise blockchain and normal blockchain networks also known as public blockchains is that enterprise blockchains can be private and the participants in the network can be decided by the business owner contrary to this in public blockchain networks anyone can be a participant. To know more you can check out this blog on Blockchain for business.

So let’s continue with Hyperledger Fabric and see what are the features it provides us with :

  1. Permissioned Network: Hyperledger Fabric is a framework for permissioned networks, where all participants have known identities. Many use cases — in the financial sector and healthcare industry, in particular — are subject to data protection laws that require knowing who the members of the network are and who is accessing specific data.
  1. Performance, scalability, and levels of trust: Hyperledger Fabric stores various transactions happening in different aspects. It also focuses on reducing several layers of trust. Also, it has got a huge number of verification done on the transactions. It is very useful when you need to make speedy transactions without any hassle. It provides low latency and high throughput. It is very flexible and scalable at the enterprise level.
  1. Data on a need-to-know basis: The confidentiality of personal data is very important in a business blockchain network. Hyperledger Fabric allows for data to go to only the parties that need to know.
  1. Modular architecture supporting plug-in components: The modularity of Hyperledger Fabric architecture enables network designers to plug in their preferred implementations for components, which is an advantage. It allows the company to use its already existing identity management system, increasing reusability, and reducing cost.

If you are looking for a blockchain platform for your business use case Hyperledger Fabric is something you would want to consider.

So now that we understood why should we use Hyperledger Fabric, let’s move on and see how we can use DAML and Hyperledger Fabric together.

DAML and HACERA

So we have been talking about DAML so much and we know how awesome a language it is for making smart contracts, but it is new to the smart contract world, and if you are already a hyperledger Fabric user or have some knowledge about Hyperledger projects you would know that Hyperledger does not support DAML directly currently. But don’t worry, you can still deploy your DAML application on a Fabric ecosystem.

How do we do that!?

The answer is Unbounded SCALE, a product by HACERA which brings DAML to the Hyperledger Fabric ecosystem. It was created to support the seamless development of DAML based workflows to deploy them in a highly regulated environment.

Just take your DAML application and use Unbounded SCALE as a medium to deploy your application on HYperledger Fabric and BOOM !

We would still need to learn about Unbounded SCALE so it’s not all easy but, you won’t have to worry about understanding Hyperledger Fabric infrastructure doing all the core technical stuff.

Now we know how can we deploy our DAML application on the Hyperledger Fabric ecosystem, using the Unbounded SCALE. You can create private multiparty DLT and use it. We will see how we can use the Unbounded SCALE to do these things in future blogs. 

In this blog we will use “daml-on-fabric” open source project for deploying DAML on a single node Fabric environment.

Daml-on-fabric

Daml-on-fabric is an opensource project which is maintained by digital asset and is an implementation of DAML ledger that stores data using Hyperledger Fabric 2.1

Let’s check the Prerequisites for running this project.

  1. Linux/macOS
  2. Docker CE version 19.03.2 – You can install docker from here
  3. Docker-compose – Download it from here.
  4. Java / JDK version 1.8.0.x
  5. Scala version 2.12.11
  6. SBT version 1.2.8
  7. Fabric SDK Java version 2.1.0
  8. Fabric version 2.1.0
  9. DAML SDK version 1.2.0-snapshot-

Note: Make sure that the DAML SDK version in the built.sbt and your daml project match.

You can get the latest Hyperledger Fabric binaries and tools from the following command: This will download the necessary fabric tools binaries to /bin under the directory from which it is run

curl -sSL https://bit.ly/2ysbOFE | bash -s — 2.1.0 -s

Now add the path in your .bashrc using the following commands

  1. Open .bashrc

nano ~/.bashrc

2. Add the path to the file using

export PATH=<download_directory>/bin:$PATH

3. Save the file and run

source .bashrc

The next step is to set up our project.

Clone the repository using :

git clone git@github.com:digital-asset/daml-on-fabric.git

This will create a directory daml-on-fabric with all the project contents.

Now that we have our project all setup. We will continue and start our local Hyperledger Fabric environment.

Running a local Hyperledger environment

To run our local Hyperledger environment follow these steps :

cd ~/daml-on-fabric/src/test/fixture/

./gen.sh

./restart_fabric.sh

This will start a Docker-compose network that will setup fabric for the development environment. This example set up a network of  5 peers, of which two will be for endorsement.

Note : If you are using a Linux based system it is possible you may not be able to run the ledger if you immediately use the sbt command after running your fabric network. If you face this problem, leave your network up for 5 mins and then run the sbt command to run the ledger.

Services and role

There are several roles that define which parts of the service are going to be executed:

  • provision: will connect to Fabric and prepare it to be used as storage for a DAML ledger.
  • ledger: will run a DAML Ledger API endpoint at a port specified with –port argument.
  • time: will run a DAML time service, which writes heartbeats to the ledger. There should be exactly one-time service per ledger.
  • explorer: will run a block explorer service that exposes a REST API to view the content of blocks and transactions inside the Fabric network for debugging or demonstration purposes. 

One ledger may perform multiple roles at the same time, in which case roles are separated with a comma. 

Now that our network is up we will now deploy a quickstart project 

Deploying DAML on Fabric

Follow these steps to create a quickstart project

cd ~/daml-on-fabric

daml new quickstart quickstart-java

cd ~/quickstart/

daml build

We now have a quickstart daml application. We will now run the ledger with this application.

Run the Ledger with Quick Start DAR archive

cd ~/daml-on-fabric/

sbt “run –port 6865 –role provision,time,ledger,explorer ./quickstart/.daml/dist/quickstart-0.0.1.dar”

Now that your ledger is up and running we need to allocate the parties which are defined in the application to the ledger as there is no automatic mapping of DAML parties to parties on the Fabric ledger.

You can allocate parties to the ledger by using the command 

cd ~/quickstart/

daml ledger allocate-parties –host localhost –port 6865 Alice Bob Carol USD_Bank EUR_Bank

Now we have deployed our application on a single node fabric environment. Now i want to know if my application is interacting well with the fabric. For this we will use the navigator.

Run DAML Navigator

To start the navigator use :

cd ~/quickstart/

daml navigator server localhost 6865 –port 4000

This will start the navigator at https://localhost:4000

That’s it! we are done. We have now deployed our daml application on a single node Fabric environment.

Now keep in mind that the versions of this project may change in future as the application grows. I will try my best to keep this blog updated but in case i am not able to, below in the references you will find the github link of this project. Follow the README.md and you will be able to run the project.

References :

  1. https://github.com/digital-asset/daml-on-fabric – Github repo
  2. https://hacera.com/products/scale/
  3. https://hyperledger-fabric.readthedocs.io/en/release-2.0/

Knoldus-blog-footer-image