First Contract
-- FirstContract.daml module FirstContract where -- A template defines the structure and rules of a contract. -- `with` declares the contract's fields. -- `where` contains the rules: signatories, observers, choices. template Asset with issuer : Party -- who created the asset owner : Party -- current holder name : Text -- human-readable label amount : Decimal -- quantity where -- At least one signatory is required. -- Signatories must authorize the creation of this contract. signatory issuer -- Observers can see the contract but cannot act on it. observer owner -- `ensure` is a contract invariant checked on every creation. -- If False, the transaction is aborted. ensure amount > 0.0 -- The `agreement` field is an optional human-readable string. agreement show issuer <> " issued " <> show amount <> " of " <> name <> " to " <> show owner
Key points
Template structure
- A
templateproduces a record type of the same name that is used to constructcreatecommands. - DAML is not object-oriented. Templates do not inherit from each other; use interfaces for polymorphism.
Contract lifecycle
thisrefers to the current contract's data inside a choice body.selfrefers to theContractIdof the current contract inside a choice body.- A
ContractId Tis a typed reference to an active contract. It becomes stale (unusable) once the contract is archived.
Configuration
signatory,observer,ensure, andagreementare evaluated when the contract is created.