Extending DAML applications

Note: Cross-SDK extensions require DAML-LF 1.8 or newer. This is the default starting from SDK 1.0. For older releases add build-options: ["--target=1.8"] to your daml.yaml to select DAML-LF 1.8.

Consider the following simple DAML model for carbon certificates:

module CarbonV1 where

template CarbonCert
  with
    issuer : Party
    owner : Party
    carbon_metric_tons : Int
  where
    signatory issuer, owner

It contains two templates. The above template representing a carbon compensation certificate. And a second template to create the CarbonCert via a Propose-Accept workflow.

Now we want to extend this model to add trust labels for certificates by third parties. We don’t want to make any changes to the already deployed model. Changes to a DAML model will result in changed package ID’s for the contained templates. This means that if a DAML model is already deployed, the modified DAML code will not be able to reference contracts instantiated with the old package. To avoid this problem, it’s best to put extensions in a new package.

In our example we call the new package carbon-label and implement the label template like

module CarbonLabel where

import CarbonV1

template CarbonLabel
  with
    cert : ContractId CarbonCert
    labelOwner : Party
  where
    signatory labelOwner

The CarbonLabel template references the CarbonCert contract of the carbon-1.0.0 packages by contract ID. Hence, we need to import the CarbonV1 module and add the carbon-1.0.0 to the dependencies in the daml.yaml file. Because we want to be independent of the DAML SDK used for both packages, we import the carbon-1.0.0 package as data dependency

name: carbon-label
version: 1.0.0
dependencies:
  - daml-prim
  - daml-stdlib
data-dependencies:
  - path/to/carbon-1.0.0.dar

Deploying an extension is simple: Just upload the new package to the ledger with the daml ledger upload-dar command. In our example the ledger runs on the locahost:

daml ledger upload-dar --ledger-port 6865 --ledger-host localhost ./daml/dist/carbon-label-1.0.0.dar

If instead of just extending a DAML model you want to modify an already deployed template of your DAML model, you need to perform an upgrade of your DAML application. This is the content of the next section.