DAML: Build Powerful Smart Contracts

Reading Time: 4 minutes

As the blockchain technology evolves, there is a need for improved frameworks through which users can create and deploy smart contracts. DAML is one such open-source language for smart contracts originated by Digital Asset.

In this blog, we will be understanding about the features of DAML, it’s need and benefits in the current scenarios and the steps to get started with building smart contracts using DAML.

What are smart contracts ?

Let us first try to understand smart contracts and how do they differ from regular contracts .

First, a contract is a legally binding document between two parties which is also legally enforceable. simple right? it’s just a document which makes sure that both the parties understand each other and have agreed to the requirements. so, how are smart contracts different from contracts?

Smart contracts are simple, difference in comparison to normal contracts is that the contract written is machine readable and also executable, without the involvement of any third party. Smart contracts help you exchange money, property, shares, or anything of value in a transparent, conflict-free way while avoiding the services of a middleman.

What is DAML?

Digital Asset modelling Language is an open source programming language used to write distributed applications quickly, concisely and correctly. 

It is functional and was designed for distributed business workflow. It helps a developer to focus more on programming business processes by cutting down the amount of time the developer would spend on dealing with encryption and block chain.

  • It is very easy to write! So you don’t need to be an expert developer to work with it but need to be familiar with the business defined.
  • It was designed to let us build and deploy our applications very quickly.
  • It is more focused on business logic.
  • It provides high contract privacy as the system keeps track of all parties which are allowed to see the contracts.

What problem is it trying to solve ?

  • Time Consumption – Clients always want to provide service to the user. The end user does not care about the tech stack we use to build the application as long as user’s needs are fulfilled. In reality building these applications can take a lot of time which is the cost the client has to bear reducing their profits.
  • Tightly coupled Architecture – Most of the applications written are tightly coupled to the underlying infrastructure, which makes it very costly and difficult to port the application to another type of infrastructure.

Benefits of DAML

  • Open Source – It is open source since April, 2019 thus attracting developers from around the world to tinker with it and add new features.
  • Increased productivity – Focus of developers is more on automating the business process by writing for Distributed ledger rather than the infrastructure. Cryptography, hashing and application distribution is overseen by DAML.
  • Infrastructure independent – It is available on a number of databases and distributed ledger which allows us to write the application first and then decide the infrastructure that best fits the application.

Interesting right? Let’s Get Started with DAML !

  1. For building applications with it we first need to install few Prerequisites and then SDK.
  2. The SDK is available for Windows, macOS and Linux. In this guide, we will be using Linux.

Installing Prerequisites 

  • Install Visual Studio IDE 
  • JDK 8 or greater.

To install jdk 8 or greater follow the steps for ubuntu:

  • First, update the package index

sudo apt-get update

  • install the JDK with the following command:

sudo apt-get install default-jdk

Install the SDK

To install the SDK on Mac or LInux 

curl -sSL https:// get.daml.com / | sh

After you have installed the SDK it will ask you to add ~/.daml/bin to PATH.

To do so (ubuntu) –

  • Open terminal and type the command : nano ~/.bashrc

Now you will need to add the directory path of DAML which can look something like :  home/knoldus/.daml.bin

  • Add this path in bashrc using :  

export PATH=$PATH:”Directory path”

That’s it, You’re Done ! Now you are ready to build applications.

To make the project setup easier, DAML provides a daml assistant which is a command line tool that does a lot of things related to the SDK.

Using assistant you can: 

  • Create a new DAML project using :
daml new <path to create project in>
  • Initialize a new DAML project
 daml init
  • Compile the project :
daml build

There are many commands you can use for your project with a daml assistant. Run :

daml --help 

This will list you all the things that assistant provides.

Moving on let’s download a quickstart application in DAML

To make things easy for us we will use the daml assistant for downloading and setting up our quickstart application. We can download and set up the application manually too, but I would recommend you all to use assistant to its full potential as it make things easy for a developer.

To download our quickstart application using daml assistant:

daml new quickstart quickstart-java

This will create a quickstart-java application in the new folder named quickstart.

cd quickstart

This will lead us to the current directory.
Now you can manually go to the project location and see the content of the project or you can use the command ls in the terminal which will list the content of the directory you are in.