Build Your First Canton App
Set up your tools, create a Daml project, and test a contract.
What Can You Build on Canton?
Canton supports applications where multiple parties share a workflow but need different permissions and views of its data. Daml lets you model who can propose, approve or complete each action. This makes it useful for agreements and asset workflows that cross organizational boundaries.
For a first project, choose a small workflow with two parties and one clear change of state:
- A license offer: a provider creates an offer and a named customer accepts it, producing a license.
- An asset transfer: an issuer creates an asset and its owner transfers it to another party.
- A purchase approval: one party submits a request and another approves or rejects it.
Tokenized assets, collateral management and settlement are larger applications of these ideas. Start with the permissions and state changes before adding money, external data or production integrations.
Your First Daml Project
Start from a dpm new project and finish with a Daml model that builds and passes its tests.
Before You Start
Install DPM, the Daml package manager, then follow the SDK setup instructions. Check the prerequisites and supported platforms before starting.
Review the application security practices before modelling your workflow: identify the parties, which actions each may authorize, and who should see each contract.
Model Your Workflow in Daml
If Daml is new to you, start with the official documentation on contract templates, then testing Daml contracts. Use these to understand the model and tests below.
Create a project:
bashdpm new my-app cd my-appdpm newuses theskeletontemplate by default. The project has two packages:main/holds your model andtest/holds its Daml Script tests.Write your workflow in
main/daml/Main.daml. The skeleton Asset illustrates an issuer-signed contract whose owner can transfer it. The example limits names to 100 characters to bound the stored input. It is a minimal asset model, not a token-standard implementation.damlmodule Main where import DA.Text qualified as T type AssetId = ContractId Asset template Asset with issuer : Party owner : Party name : Text where ensure name /= "" && T.length name <= 100 signatory issuer observer owner choice Give : AssetId with newOwner : Party controller owner do create this with owner = newOwnerTest each rule your model enforces. Add
import DA.Text qualified as Ttotest/daml/Test.daml, then add a test that a name over the limit is refused:daml-- An asset name longer than 100 characters is refused. nameTooLong : Script () nameTooLong = script do alice <- allocateParty "Alice" submitMustFail alice do createCmd Asset with issuer = alice owner = alice name = T.implode (replicate 101 "x")Generate Java or TypeScript Bindings
Build both packages, then generate bindings from your model's DAR. Run these from the project root:
bashdpm build --all dpm codegen-java main/.daml/dist/my-app-main-0.0.1.dar -o generated-java dpm codegen-js main/.daml/dist/my-app-main-0.0.1.dar -o generated-tsdpm build --allwrites each package's DAR to<package>/.daml/dist/<name>-<version>.dar.dpm codegen-javawrites a Java class per template and per choice, heregenerated-java/main/Asset.javaandgenerated-java/main/Give.java. Your backend uses them to create contracts and exercise choices without building gRPC messages or JSON payloads by hand. Add the Daml Java bindings library as a dependency; its Maven coordinates are in the Daml SDK releases.dpm codegen-jswrites an npm package for each Daml package. Use the generated bindings to build typed requests for the JSON Ledger API, and install the peer dependencies listed in the generated package.The Java and JavaScript codegen pages list every flag.
Test Your Project
Run the tests from the
test/package:bashcd test && dpm testThe test summary has one line per test:
Outputdaml/Test.daml:nameTooLong: ok, 0 active contracts, 1 transactions. daml/Test.daml:setup: ok, 1 active contracts, 3 transactions.
Next: Test the Integrated App on LocalNet
Your model now builds and passes its Daml Script tests. Use LocalNet to test the frontend, backend and network services together.
Follow the LocalNet guide when adding application services. Test submission, ledger updates and failure handling through the application.
For a separate React example, BootNode’s Canton dAppBooster tutorial walks through a note-and-acknowledgement workflow with wallet integration. Use it to study the connection between the interface, the user’s approval and the Daml choices.