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:
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
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
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 localhost:
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.