Daml SDK and Canton¶
In this tutorial, you will learn how to run the Create Daml App example on Canton. This guide (together with the Daml SDK getting started guide), will teach you
- The main concepts of Daml
- How to compile your own Daml Archive (DAR)
- How to run the Create Daml App example on Canton
- How to write your own Daml code
- How to integrate a conventional application with Canton
This tutorial builds on the Daml tutorial and mainly covers the difference of running the example on a distributed setup using Canton instead of running it on the Daml sandbox. This comes with a few known problems and this section explains how to work around them.
Please run through the original Daml getting-started guide to familiarise yourself with what you are going to do first. Then, come back here to get the same example running on Canton.
Please follow the Daml SDK installation guide to get the SDK locally installed.
This guide has been tested with the SDK version 1.13.0. Set the environment variable
1.13.0 so that
daml commands use this version.
Starting from the location where you unpacked the Canton distribution, fetch the create-daml-app example into a directory
create-daml-app (as the example configuration files of
examples/04-create-daml-app expect the files to be there):
daml new create-daml-app --template create-daml-app
Then, compile the Daml code into a DAR file (this will create the file
run the code generation step used by the UI:
cd create-daml-app daml build daml codegen js .daml/dist/create-daml-app-0.1.0.dar -o ui/daml.js
You will also need to install the dependencies for the UI:
cd ui npm install
Next, the original tutorial would ask you to start the Sandbox and the HTTP JSON API with
We will instead start Canton using the distributed setup
examples/04-create-daml-app, and will later start the HTTP JSON API separately.
Return to the directory where you unpacked the Canton distribution and start Canton with:
cd ../.. bin/canton -c examples/04-create-daml-app/canton.conf --bootstrap examples/04-create-daml-app/init.canton
If you get an
Compilation Failed error, you may have to make the Canton binary executable with
chmod +x bin/canton
This will start two participant nodes, and will allocate the parties Alice and Bob. Each participant node will expose its own ledger API:
- Alice will be hosted by participant1, with its ledger API on port
- Bob will be hosted by participant2, with its ledger API on port
Note that the
examples/04-create-daml-app/init.canton script performs a few setup steps to permission the parties and upload the DAR.
Leave Canton running and switch to a new terminal window.
Running the Create Daml App example¶
Once Canton is running, start the HTTP JSON API:
- Connected to the ledger api on port
12011(corresponding to Alice’s participant)
- And connected to the UI on the default expected port
DAML_SDK_VERSION=1.13.0 daml json-api \ --ledger-host localhost \ --ledger-port 12011 \ --http-port 7575 \ --allow-insecure-tokens
Leave this running. The UI can then be started from a 3rd terminal window with:
cd create-daml-app/ui REACT_APP_LEDGER_ID=participant1 npm start
Note that we have to configure the ledger ID used by the UI to match the name of the participant that we’re running against.
This is done using the environment variable
In order to login as Alice we need to know Alice’s party ID. Return to the running instance of Canton and enter the following command to the Canton console:
The resulting string is Alice’s party ID. It should look something like
"Alice::010ac60cd17d7dbf534ff89b001eb80f64cf9e27c4025dd3beca75d17dc6ec0e69", but the string after the
(ie the fingerprint) will differ.
Enter Alice’s party ID in the UI to login as Alice.
Alice can follow Bob using Bob’s party ID, obtained with
The Sandbox performs party allocation implicitly, which is why you didn’t need this step when running the Create Daml App example against Sandbox. Canton, as well as other production ledgers, requires explicit party allocation. See the Provisioning Identities section of the Ledger API documentation for more information.
Connecting to participant2¶
You can login as Bob using
participant2 by following essentially the same process as for participant1, just adjusting ports to
First, start another instance of the HTTP JSON API, this time using the options
-- ledger-port=12021 and
12021 corresponds to participant2’s ledger port, and
7576 is a new port for another instance of the HTTP JSON API.
DAML_SDK_VERSION=1.13.0 daml json-api \ --ledger-host localhost \ --ledger-port 12021 \ --http-port 7576 \ --allow-insecure-tokens
Then start another instance of the UI for Bob,
running on port
3001 and connected to the HTTP JSON API on port
cd create-daml-app/ui PORT=3001 REACT_APP_HTTP_JSON_PORT=7576 REACT_APP_LEDGER_ID=participant2 npm start
You can fetch Bob’s party ID from the Canton console to use to login to the UI with:
Now that you have glimpsed at Daml and what a full Daml-based solution looks like, it is maybe time for you to build your own first Daml application.
- Use the Daml language reference docs to master Daml and build your own Daml model.
- Test your model using Daml scripts.
- Create a simple UI following the example of the Create Daml App template used in this tutorial.
- See how to compose workflows across multiple Canton domains.
- Showcase your application on the forum.