Deploying DAML Smart Contracts on Hyperledger Sawtooth

Reading Time: 5 minutes

In our last blog, Deploying DAML based Smart Contracts on project:DABL, we deployed our daml application on project:DABL, a blockchain platform by digital asset. We also discussed how DAML provides support on multiple blockchain platforms like hyperledger sawtooth, fabric, Corda etc.

In this blog we will take a step further in our DAML journey and deploy our application on another blockchain platform which is Hyperledger Sawtooth.

Hyperledger Sawtooth

So before jumping to deployment of applications and all the technical stuff, let’s just have a small introduction to sawtooth. 

Hyperledger Sawtooth is an open source Blockchain platform founded by the Linux Foundation’s open-source blockchain project, Hyperledger. It is an enterprise-grade distributed ledger and was one of the first projects under the Hyperledger umbrella.

Hyperledger is a home to different distributed ledger frameworks like hyperledger fabric, Indy, and our today’s main focus which is hyperledger sawtooth. 

Some Advantages of hyperledger sawtooth are :

  1. Permissioned/Permission less: Sawtooth can be configured to be either permissioned or permission less. By default, Hyperledger Sawtooth is permissioned.
  2. Scaleable: sawtooth can handle large amounts of transactions. Depending on the number of transactions it can be scaled easily.
  3. Multi-Language support: sawtooth allows developing smart contracts in Python, JavaScript, Rust, C++, and Go.
  4. Loose coupling architecture. The blocks within the Sawtooth’s network are not highly dependent on each other, which means that the change that is made to one element would not affect the network as a whole. It offers smart contract abstraction to allow developers to create contract logic in the programming language of their choice.

Now that we know what hyperledger sawtooth is let’s us understand how we can take DAML application and deploy it on sawtooth

Sextant for DAML

Now working with any hyperledger platform is not the easiest of things. We do need to have a good knowledge of the platform and its underlying infrastructure. We may also need to work with some of the sawtooth dependencies which may take some time. 

To sum it up, we will need to worry about the blockchain infrastructure a little bit. Well don’t worry, we have a solution to this problem in the form of Sextant for DAML.

Sextant for DAML is a blockchain management platform that leverages this powerful combination to deliver one-click deployment of DAML-powered enterprise-grade Sawtooth networks running on industry-standard Kubernetes clusters. These can either be stand-alone – typically the case if a developer is testing a new blockchain application or smart contract – or join existing DAML-powered Sawtooth networks.

Sextant is a product of BTP(Blockchain technology partners) who are working to bring blockchain benefits to businesses and accelerating its adoption by giving a powerful blockchain platform that frees up enterprises to completely focus on application development.

It is a new management platform launched by Blockchain Technology Partners on AWS and BTP maintains this framework that gives the customers assurance of using tested versions of this framework.

In simple terms. Take your DAML application and deploy it on a sawtooth network which is managed by Sextant thus making your work easy.

Now Using Sextant to deploy our application on sawtooth is easy but will require us to explore the Sextant platform and understand its basics. We will cover this in our future blogs. 

For this blog, we will use BTP’s “daml-on-sawtooth” which is an integration of the DAML smart contract runtime engine, created and open-sourced by Digital Asset, with Hyperledger Sawtooth blockchain. It will deploy our application on a single node sawtooth network.

Let’s get started then!

Daml-on-sawtooth

It is an open-source project which is maintained by BTP. Anyone can contribute to this project.

Let’s check out the Prerequisites for running this project. 

  1. Linux/macOS – sorry windows user!
  2. Docker version 19.03.2 or higher – You can install docker from here
  3. Docker-compose – Download it from here.
  4. OpenJDK version 11 or higher
  5. NodeJS version 10.16.2 
  6. DAML SDK 

Now, once we have these dependencies installed. The next step is to set up our project. 

  1. Clone the repository using :

$ git clone git@github.com:blockchaintp/daml-on-sawtooth.git

  1. Set export build identifier environment variable using :

export ISOLATION_ID=my-local-build

This is used to distinguish different variations of builds on the same machine.

  1. Execute the local build script.

$ cd daml-on-sawtooth/

$ bin/build.sh

This will compile and package all of the java, as well as prepare docker images for local execution.

Running and shutting down daml-on-sawtooth

Now let’s see how we can start our sawtooth environment on our system.

  1. Open terminal and cd into project directory.
  2. To start single node sawtooth environment run :

./docker/run.sh start

3. To shutdown the application

./docker/run.sh stop

Now that we know how to start and shut our sawtooth environment now let’s see how we can deploy our application in this environment.

Deploying daml on sawtooth

Using the steps given above, start the sawtooth environment. Once we are done with it we can start interacting with the sawtooth using our daml assistant and deploy our application easily.

You can use own project or use a quickstart project.

Open the terminal in daml-on-sawtooth and do the following

  1. Allocate Parties that are involved in our application using :

DAML_SDK_VERSION=0.13.41 daml ledger allocate-parties PARTY –host localhost –port 9000

  1. Upload the dar using the command :

DAML_SDK_VERSION=0.13.41 daml ledger upload-dar –host localhost –port 9000 <location of darfile>

Now we have deployed our application on a single node sawtooth environment. But how do I know if my application is interacting well with the sawtooth ? Using a navigator of course! Let’s start our navigator!

Interacting with daml-on-sawtooth using daml navigator

Open the terminal in daml-on sawtooth and run the command :

DAML_SDK_VERSION=0.13.41 daml ledger navigator –host localhost –port 9000

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

Note : Port 9000 is the port where daml-on-sawtooth is opened for communications with the outside world. If you have a custom daml application, you can connect to it via this port.

That’s it ! We deployed our DAML application on another blockchain platform. 

Now one thing to note here is that this is an open source project so it is bound to change in future. It is possible that by the time you read this blog some commands may not work. Therefore I recommend you to follow the project README.md carefully and follow those steps. I will try to keep this blog updated but in case i am not able to, you should not be stuck! I will provide the Github repository link in the references.

Some things to keep in mind while running this project :

  1. Make sure that you have no running docker containers before starting this project.
  2. Make sure your ports are available to run the navigator.
  3. It is possible that after shutting down the sawtooth you may not be able to run it again. Don’t worry, just reclone the repo using the steps given above. 
  4. This project currently requires sdk 0.13.41. Make sure that your daml project is set up on the same version.

Knoldus-blog-footer-image