DAML Smart Contracts
Aula 1 de 3AvançadoUnderstand DAML, the smart contract language powering Canton.
DAML: The Language
Seção 1 de 2
DAML (Digital Asset Modeling Language) is the smart contract language for Canton. It is a strongly typed, functional language built on top of Haskell with semantics purpose-designed for multi-party, privacy-preserving workflows. Before writing any Canton application you need to understand what DAML forces you to think about, because those constraints are what make Canton applications reliable.
Templates are contracts. The fundamental DAML abstraction is the template. A template declares a data shape (the fields of the contract) and a set of choices (the actions that can be taken on the contract). You do not 'deploy a contract' the way you do on Ethereum: you instantiate templates, and each instance is a live contract on the ledger.
Signatories authorize. Every template declares one or more signatories. A signatory is a party whose authorization is required for the contract to exist: creating an instance needs the authority of every signatory. After that, the contract changes only through its choices, and each choice names the parties that can exercise it; the built-in Archive choice names the signatories. There is no 'admin key' that can unilaterally modify other parties' contracts. A party that is not a signatory can act on a contract only through a choice that names it as controller; writing the template gives you no rights over its contracts.
Observers see. Beyond signatories, a template can declare observers: parties who can see the contract. Being an observer gives no authority by itself; only a choice that names a party as controller does. This is how selective disclosure works at the language level. A regulator can be a standing observer without having any authorization rights; a custodian can see assets in custody without being a signatory on the issuing contract.
Choices have controllers. Each choice (action) declares which party or parties can exercise it. Exercising a choice runs arbitrary DAML code that can create new contracts, archive existing ones, and compute outputs. The choice's effects are visible only to parties that are authorized to see them, consistent with the privacy model.
Ledger is deterministic. DAML is a pure functional language. The same inputs always produce the same outputs. No external randomness, no network calls, no wall clock reads inside a contract body. Oracles and off-chain data come in as signed inputs, not as live reads.
Authorization, Privacy, and the Ledger Model
Seção 2 de 2
The DAML ledger model is what most distinguishes Canton from other smart contract platforms. Spending time here pays back when you write or review real DAML code.
Authorization proofs. When a choice is exercised, DAML tracks every authorization implied by the call chain. If you exercise a choice that internally creates a new contract, the new contract's signatories must be among the parties that authorize that step: the signatories of the contract the choice is exercised on and the choice's controllers. DAML checks this when the transaction is interpreted, and every node that validates the transaction checks it again; a transaction that lacks the authority is rejected. It is not a compile-time check: code that would lack authority compiles, and fails when it runs. This is how DAML prevents the 'permission creep' bugs that plague Solidity.
Sub-transaction privacy via projection. When a multi-party transaction executes, each involved party receives a projection of the transaction: the subset of actions and data they are authorized to see. Parties who were only tangentially involved (e.g. a fee recipient) see only the actions relevant to them, cryptographically certified against the full transaction without ever seeing the full transaction. This is baked into the runtime, not a library.
The ledger is virtual, not one shared chain. Canton's documentation describes a virtual global ledger: the union of what all parties see, which no single node stores in full. Each node keeps only the contracts and transactions of the parties it hosts, so two applications that never share a contract never see each other's data, even on the same synchronizer. Contrast with Ethereum, where every node keeps all contracts and the whole shared state.
Archiving vs deletion. When a DAML contract is 'archived', it becomes inactive: no one can exercise a choice on it again, but archiving does not erase it. The nodes of its parties keep its history, which is what lets you prove 'this contract existed at this time and was archived at this later time'. A node's operator can prune archived contracts and old transactions after a retention period, so how long that history stays available depends on each node's retention policy.
Divulgence. A niche but important concept: parties who need to know a contract exists, even without being formal signatories or observers, can receive divulged information as a byproduct of legitimate transactions. This is bounded and auditable, but developers need to understand it to avoid inadvertent information leaks. To give another party read access to a contract on purpose, Canton provides explicit disclosure.