├── .github
└── workflows
│ └── cla.yml
├── .gitignore
├── LICENSE
├── README.md
├── _config.yml
├── _data
└── blocks.yml
├── _includes
├── blocks.html
├── en
│ ├── Basics.md
│ ├── Choices.md
│ ├── CommandLine.md
│ ├── Concepts.md
│ ├── ContractKeys.md
│ ├── Data.md
│ ├── Functions.md
│ ├── JavaScript.md
│ ├── Resources.md
│ ├── Scripts.md
│ ├── Templates.md
│ ├── Types.md
│ ├── Updates.md
│ └── What-is.md
└── header.html
├── _layouts
└── default.html
├── cheatsheet.css
├── daml-logo.png
└── index.html
/.github/workflows/cla.yml:
--------------------------------------------------------------------------------
1 | name: "CLA Assistant"
2 | on:
3 | issue_comment:
4 | types: [created]
5 | pull_request_target:
6 | types: [opened,closed,synchronize]
7 |
8 | # explicitly configure permissions, in case your GITHUB_TOKEN workflow permissions are set to read-only in repository settings
9 | permissions:
10 | actions: write
11 | contents: write # this can be 'read' if the signatures are in remote repository
12 | pull-requests: write
13 | statuses: write
14 |
15 | jobs:
16 | CLAAssistant:
17 | runs-on: ubuntu-latest
18 | steps:
19 | - name: "CLA Assistant"
20 | if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have hereby read the Digital Asset CLA and agree to its terms') || github.event_name == 'pull_request_target'
21 | uses: digital-asset/cla-action@v0.0.2
22 | env:
23 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 | # the below token should have repo scope and must be manually added by you in the repository's secret
25 | # This token is required only if you have configured to store the signatures in a remote repository/organization
26 | PERSONAL_ACCESS_TOKEN: ${{ secrets.PAT_FG_CCI_VALIDATOR_CLA }}
27 | with:
28 | path-to-document: 'https://github.com/digital-asset/daml/blob/main/CODE_OF_CONDUCT.md' # e.g. a CLA or a DCO document
29 | # branch should not be protected
30 | branch: 'main'
31 | allowlist: bot*
32 | custom-notsigned-prcomment: '🎉 Thank you for your contribution! It appears you have not yet signed the Agreement [DA Contributor License Agreement (CLA)](https://gist.github.com/digitalasset-cla), which is required for your changes to be incorporated into an Open Source Software (OSS) project. Please kindly read the and reply on a new comment with the following text to agree:'
33 | custom-pr-sign-comment: 'I have hereby read the Digital Asset CLA and agree to its terms'
34 | custom-allsigned-prcomment: '✅ All required contributors have signed the CLA for this PR. Thank you!'
35 | # Remote repository storing CLA signatures.
36 | remote-organization-name: DACH-NY
37 | remote-repository-name: cla-action-data
38 | # Branch where CLA signatures are stored.
39 | path-to-signatures: signatures/signatures.json
40 |
41 | # the followings are the optional inputs - If the optional inputs are not given, then default values will be taken
42 | #remote-organization-name: enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository)
43 | #remote-repository-name: enter the remote repository name where the signatures should be stored (Default is storing the signatures in the same repository)
44 | #create-file-commit-message: 'For example: Creating file for storing CLA Signatures'
45 | #signed-commit-message: 'For example: $contributorName has signed the CLA in $owner/$repo#$pullRequestNo'
46 | #custom-notsigned-prcomment: 'pull request comment with Introductory message to ask new contributors to sign'
47 | #custom-pr-sign-comment: 'The signature to be committed in order to sign the CLA'
48 | #custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.'
49 | #lock-pullrequest-aftermerge: false - if you don't want this bot to automatically lock the pull request after merging (default - true)
50 | #use-dco-flag: true - If you are using DCO instead of CLA
51 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.jl.cov
2 | *.jl.*.cov
3 | *.jl.mem
4 | deps/deps.jl
5 | .vscode
6 | _site
7 | .jekyll-cache
8 | .jekyll-metadata
9 | default.nix
10 | .envrc
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2015 Ian Hellström
4 | Copyright (c) 2016 Harris Brakmic
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.daml.com)
2 |
3 | [](https://github.com/DACH-NY/daml-cheat-sheat/blob/master/LICENSE)
4 |
5 | Copyright 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All Rights Reserved.
6 | SPDX-License-Identifier: MIT
7 |
8 | # Daml Cheat-Sheet
9 |
10 | This repository contains the source code behind the Daml cheat-sheet.
11 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | title: The Fast Track to Daml
2 | baseurl: "." # this needs to be set for deployment!
3 | description: "The Fast Track to Daml - Daml Cheat Sheet"
4 | github_username: digitalasset
5 | markdown: kramdown
6 |
7 | t:
8 | en:
9 | name: "English"
10 | fast-track: "The Fast Track to "
11 | quick-dirty: "The TL;DR; for "
12 | github-1: "This page's source is"
13 | github-2: "located here"
14 | github-3: "Pull requests are welcome!"
15 | translate: "Help translate!" # Not used for `en`
16 |
--------------------------------------------------------------------------------
/_data/blocks.yml:
--------------------------------------------------------------------------------
1 | - file: What-is.md
2 | title: What is…?
3 | - file: Concepts.md
4 | title: Concepts
5 | - file: CommandLine.md
6 | title: Command line tools
7 | - file: Basics.md
8 | title: Basics
9 | - file: Types.md
10 | title: Types
11 | - file: Data.md
12 | title: Data
13 | - file: Functions.md
14 | title: Functions
15 | - file: Templates.md
16 | title: Contract Templates
17 | - file: ContractKeys.md
18 | title: Contract keys
19 | - file: Choices.md
20 | title: Choices
21 | - file: Updates.md
22 | title: Updates
23 | - file: Scripts.md
24 | title: Scripts
25 | - file: JavaScript.md
26 | title: JavaScript/React API
27 | - file: Resources.md
28 | title: DAML resources
29 |
--------------------------------------------------------------------------------
/_includes/blocks.html:
--------------------------------------------------------------------------------
1 |
23 |
--------------------------------------------------------------------------------
/_includes/en/Basics.md:
--------------------------------------------------------------------------------
1 | | | |
2 | | -------------------- | ----------------------------------------------------- |
3 | | End-of-line comment | `let i = 1 -- This is a comment` |
4 | | Delimited comment | `{- This is another comment -}` |
5 |
6 | Every Daml file starts with a module header like this:
7 |
8 | ```
9 | module Foo where
10 | ```
11 |
--------------------------------------------------------------------------------
/_includes/en/Choices.md:
--------------------------------------------------------------------------------
1 | The choices of a contract template specify the rules on how and by whom contract data can be
2 | changed.
3 |
4 | ```
5 | (nonconsuming) choice NameOfChoice : ()
6 | -- optional nonconsuming annotation, name and choice return type
7 | with
8 | party1 : Party -- choice arguments
9 | party2 : Party
10 | i : Int
11 | controller party1, party2 -- parties that can execute this choice
12 | do -- the update that will be executed
13 | assert (i == 42)
14 | create ...
15 | exercise ...
16 | return ()
17 | ```
18 |
19 | Choices can be `consuming` or `nonconsuming`.
20 |
21 | | -------------------- | ----------------------------------------------------- |
22 | |`consuming`| The default. The contract is consumed by this choice. Trying to exercise another choice on the same contract id will fail.|
23 | |`nonconsuming`| The contract is not consumed by this choice and more choices can be exercised. |
24 |
--------------------------------------------------------------------------------
/_includes/en/CommandLine.md:
--------------------------------------------------------------------------------
1 | | | |
2 | | -------------------- | ----------------------------------------------------- |
3 | | Install the daml assistant | `curl -sSL https://get.daml.com | sh -s ` |
4 | | Create a new Daml project | `daml new ` |
5 | | Create a new Daml/React full stack project | `daml new --template create-daml-app` |
6 | | Start the IDE | `daml studio` |
7 | | Build project | `daml build` |
8 | | Build project, start the sandbox and JSON-API | `daml start` |
9 | | Start the sandbox ledger (in wall-clock time-mode) | `daml sandbox` |
10 | | Start the sandbox ledger (in static time-mode) | `daml sandbox --static-time` |
11 | | Start the JSON-API server (requires a running ledger) | `daml json-api --ledger-host localhost --ledger-port 6865 --http-port 7575`|
12 | | Upload a dar to the ledger | `daml ledger upload-dar ` |
13 | | Run all test scripts and output test coverage report | `daml test --show-coverage --all --files Test.daml` |
14 | | Project configuration file | `daml.yaml` |
15 |
--------------------------------------------------------------------------------
/_includes/en/Concepts.md:
--------------------------------------------------------------------------------
1 | | -------------------- | ----------------------------------------------------- |
2 | | `Party` | A party represents a person or legal entity (for example a bank). Parties can create contracts and exercise choices and are represented by the `Party` data type in Daml.
|
3 | | `Signatories, observers, and controllers` | Signatories, observers, and controllers are parties involved in actions taken on a contract, i.e., actions that are *exercised* on a contract. Signatories, observers, and controllers are therefore represented by the `Party` data type. They control who can read, create and archive a contract.
|
4 | | `Contract` | Contracts are created from blueprints called `templates` - this is the Daml code you write. Templates include:
- contract data (e.g., date, description, parties involved etc.) - roles (signatory, observer) - choices and their respective controllers (*who* gets to do *what*)
Every contract is a *template instance* stored as a row on the ledger. Contracts are immutable: once they are created on the ledger, the information in the contract cannot be changed. In order to "change" a contract you need to create a new one with the desired contract data.
|
5 | | `Choice` | A choice is something that a party can exercise (take action) on a contract. Choices give you a way to transform the data in a contract: while the contract itself is immutable, you can write a choice that archives the contract and creates a new version of it with the updated data.
A choice can only be exercised by its controller and contains the `authorization` of all of the contract's signatories as well as of the controller.
|
6 | | `Ledger` | The ledger represents the database where all contracts are recorded. More information on Daml Ledgers can be found here.
|
7 |
8 | If you are interested you can find the detailed glossary here and a free online course here.
9 |
--------------------------------------------------------------------------------
/_includes/en/ContractKeys.md:
--------------------------------------------------------------------------------
1 | Contract keys are unique and stable references to a contract that won't change even if the contract
2 | id of that contract changes due to an update.
3 |
4 | Contract keys are optional.
5 |
6 | Contract keys have an associated set of key maintainer parties. These parties guarantee the uniquess
7 | of their maintained keys.
8 |
9 | Contract keys are specified on a contract template with the `key` and `maintainer` keywords. If you
10 | specify a `key` you also have to specify its `maintainers`.
11 |
12 | | -------------------- | ----------------------------------------------------- |
13 | | `key` | Can be any expression of the contract arguments that does _not_ contain a contract id. It _must_ include all maintainer parties specified in the `maintainer` field. |
14 | |`maintainer` | Keys are unique for all specified maintainers. The maintainers need to be a projection of the expression specified with `key`.|
15 |
--------------------------------------------------------------------------------
/_includes/en/Data.md:
--------------------------------------------------------------------------------
1 | | | |
2 | | -------------------- | ----------------------------------------------------- |
3 | | Record | `data MyRecord = MyRecord { label1 : Int, label2 : Text}` |
4 | | Product type | `data IntAndText = IntAndText with myInt : Int, myText : Text` |
5 | | Sum type | `data IntOrText = MyInt Int | MyText Text` |
6 | | Record with type parameters | `data MyRecord a b = MyRecord {label1 : a, label2 : b}` |
7 | | Deriving Show/Eq instances | `data MyRecord = MyRecord {label : Int} deriving (Show, Eq)` |
8 |
--------------------------------------------------------------------------------
/_includes/en/Functions.md:
--------------------------------------------------------------------------------
1 | | ------------------------ | ------------------------------------------------- |
2 | | Signature | `f : Text -> Text -> Text`
3 | | Definition | `f x y = x <> " " <> y` |
4 | | Lambda definition | `\x y -> x <> y` |
5 | | Polymorphic functions | `f : (Show a, Eq a) => a -> Text -> Text`|
6 | | Function application | `f "hello" "world!"` |
7 | | Partial application of functions | `salute : Text -> Text` `salute = f "Hello"`|
8 |
9 | Functions are first class members of Daml, in particular, functions can be arguments to functions
10 | ```
11 | apply : (Text -> Text) -> Text -> Text
12 | apply h x = h x
13 |
14 | apply salute "John" -- "Hello John"
15 | ```
16 |
--------------------------------------------------------------------------------
/_includes/en/JavaScript.md:
--------------------------------------------------------------------------------
1 | Daml ledgers expose a unified API for interaction.
2 |
3 | The following describes how to interact with a ledger using the TypeScript libraries `@daml/ledger`, `@daml/react` in a
5 | frontend build with React .
6 |
7 | Import the libraries via:
8 |
9 | ```
10 | import Ledger from @daml/ledger
11 | import {useParty, ...} from @daml/react
12 | ```
13 |
14 | React entry point:
15 |
16 | ```typescript
17 | import DamlLeddger from @daml/react
18 |
19 | const App: React.FC = () => {
20 |
22 | httpBaseUrl?:
23 | wsBaseUrl?:
24 | party:
25 | >
26 |
27 |
28 | };
29 | ```
30 |
31 | | -------------------- | ----------------------------------------------------- |
32 | | Get the logged in party | `const party = useParty();` `...` `
You're logged in as {party}
`|
33 | | Query the ledger | `const {contracts: queryResult, loading: isLoading, } = useQuery(ContractTemplate, () => ({field: value}), [dep1, dep2, ...]) ` |
34 | | Query for contract keys | `const {contracts, loading} = useFetchByKey(ContractTemplate, () => key, [dep1, dep2, ...])` |
35 | | Reload the query results | `reload = useReload();` `...` `onClick={() => reload()}`|
36 | | Query the ledger, returns a refreshing stream | `const {contracts, loading}` = useStreamQuery(ContractTemplate, () => ({field: value}), [dep1, dep2, ...]) ` |
37 | | Query for contract keys, returns a refreshing stream | `const {contracts, loading} = useStreamFetchByKey(ContractTemplate, () => key, [dep1, dep2, ...])` |
38 | | Create a contract on the ledger | `const ledger = useLedger();` `const newContract = await ledger.create(ContractTemplate, arguments)`|
39 | | Archive a contract on the ledger | `const ledger = useLedger();` `const archiveEvent = await ledger.archive(ContractTemplate, contractId)`|
40 | | Exercise a contract choice on the ledger | `const ledger = useLedger();` `const [choiceReturnValue, events] = await ledger.exercise(ContractChoice, contractId, choiceArguments)`|
41 |
--------------------------------------------------------------------------------
/_includes/en/Resources.md:
--------------------------------------------------------------------------------
1 | - [Official documentation](https://docs.daml.com)
2 | - [The Daml code repository](https://github.com/digital-asset/daml)
3 | - [A Daml project template](https://github.com/digital-asset/create-daml-app)
4 | - [Read about how people are using Daml on the Daml Blog](https://daml.com/blog)
5 |
--------------------------------------------------------------------------------
/_includes/en/Scripts.md:
--------------------------------------------------------------------------------
1 | Daml script is a scripting language to run Daml commands against a ledger. For example:
2 |
3 | ```
4 | module Test where
5 |
6 | import Daml.Script
7 |
8 | test : Script ()
9 | test = do
10 | alice <- allocateParty "Alice"
11 | bob <- allocateParty "Bob"
12 | c <- submit alice $ createCmd NewContract with ...
13 | submit bob $ exerciseCmd c Accept with ...
14 | ```
15 |
16 | Scripts are compiled like usual Daml code to a `dar` package with the `daml build` command.
17 |
18 | | -------------------- | ----------------------------------------------------- |
19 | | Running a script | `daml script --dar example-0.0.1.dar --script-name ModuleName:scriptFunction --ledger-host localhost --ledger-port 6865`
20 | | Running a script with initial arguments given | `daml script --dar example-0.0.1.dar --input-file arguments_in_damllf_json.json --script-name ModuleName:scriptFunction --ledger-host localhost --ledger-port 6865` |
21 | | Allocating a party on the ledger | `alice <- allocateParty "Alice"` |
22 | | List all known parties on the ledger | `parties <- listKnownParties` |
23 | | Query for a given contract template visible to a given party | `query @ExampleTemplate alice` |
24 | | Create a new contract | `createCmd ExampleTemplate with ...` |
25 | | Exercise a choice on a contract | `exerciseCmd contractId ChoiceName with ... ` |
26 | | Exercise a choice on a contract by contract key | `exerciseByKeyCmd contractKey ChoiceName with ... ` |
27 | | Create and then exercise a choice on the created contract | `createAndExerciseCmd (ExampleTemplate with ... ) (ChoiceName with ...)` |
28 | | Pass time on the ledger (only applicable for a ledger running in **STATIC TIME MODE**, like the in-memory ledger of Daml Studio or `daml test`) | `passTime (hours 10)` |
29 | | Set time on the ledger (only applicable for a ledger running in **STATIC TIME MODE**, like the in-memory ledger of Daml Studio or `daml test`) | `setTime (time (date 2007 Apr 5) 14 30 05)` |
30 |
--------------------------------------------------------------------------------
/_includes/en/Templates.md:
--------------------------------------------------------------------------------
1 | Contract templates describe data that will be stored on the ledger. Templates determine who can read
2 | and write data; and by whom and how this data can be altered.
3 | A contract template is defined with the `template` keyword:
4 |
5 | ```
6 | template MyData
7 | with
8 | i : Int
9 | party1 : Party
10 | party2 : Party
11 | dataKey : (Party, Text)
12 | where
13 | signatory party1
14 | observer party2
15 | key dataKey : (Party, Text)
16 | maintainer key._1
17 |
18 | choice MyChoice : ()
19 | ...
20 | ```
21 |
22 | `with` and `where` are keywords to structure the template.
23 |
24 | | -------------------- | ----------------------------------------------------- |
25 | | `signatory` | Observes the contract and its evolution. Gives the signatory's authority to all the defined contract updates in the contract choices. |
26 | | `observer` | Observes the contract and its evolution. |
27 | | `key` | A field of the contract data used as primary index of contracts defined by this template, see `Contract Keys`. |
28 | | `maintainer` | A set of parties that guarantee uniqueness of contract keys of this template on the ledger, see `Contract Keys`. |
29 |
30 |
--------------------------------------------------------------------------------
/_includes/en/Types.md:
--------------------------------------------------------------------------------
1 | | ------------------------ | ------------------------------------------------- |
2 | | Type annotation | `myVar : TypeName`|
3 | | Builtin types | `Int, Decimal, Numeric n, Text, Bool, Party, Date, Time, RelTime` |
4 | | Type synonym | `type MyInt = Int` |
5 | | Lists | `type ListOfInts = [Int]`|
6 | | Tuples | `type MyTuple = (Int, Text)` |
7 | | Polymorphic types | `type MyType a b = [(a, b)]`|
8 |
--------------------------------------------------------------------------------
/_includes/en/Updates.md:
--------------------------------------------------------------------------------
1 | Updates specify the transactions that will be committed to the ledger. Updates are described within
2 | a `do` block:
3 |
4 | ```
5 | do
6 | cid <- create NewContract with field1 = 1
7 | , field2 = "hello world"
8 | let answer = 42
9 | exercise cid SomeChoice with choiceArgument = "123"
10 | return answer
11 | ```
12 |
13 |
14 | | -------------------- | ----------------------------------------------------- |
15 | | `create` | create an instance of the given template on the ledger `create NameOfTemplate with exampleParameters` |
16 | | `exercise` | exercise a choice on a given contract by contract id `exercise IdOfContract NameOfChoiceContract with choiceArgument1 = value1 `|
17 | | `exerciseByKey` | exercise a choice on a given contract by contract key `exerciseByKey @ContractType contractKey NameOfChoiceOnContract with choiceArgument1 = value1 ` |
18 | | `fetch` | fetch the contract data from the ledger by contract id `fetchedContract <- fetch IdOfContract `|
19 | | `fetchByKey` | fetch the contract id and data from the ledger by contract key `fetchedContract <- fetchByKey @ContractType contractKey` |
20 | | `lookupByKey` | check whether a contract with the given key exists and if yes, return the contract id `fetchedContractId <- lookupByKey @ContractType contractKey` |
21 | | `abort` | abort a transaction with an error message, the transaction will not be committed to the ledger `abort errorMessage` |
22 | | `assert` | assert that a given predicate holds, otherwise fail the transaction `assert (condition == True)` |
23 | | `getTime` | get the ledger effective time `currentTime <- getTime `|
24 | | `return` | return a value from a `do` block `return 42`|
25 | | `let` | bind a local variable or define a local function within the update `do` block `let createContract x = create NameOfContract with issuer = x; owner = x` `let answer = 42 `|
26 | | `this` | refers to the current contract data that contains this update in a choice `create NewContract with owner = this.owner` |
27 | | `forA` | run a for loop of actions over a list `forA [alice, bob, charlie] $ \p -> create NewContract with owner = p` |
28 |
--------------------------------------------------------------------------------
/_includes/en/What-is.md:
--------------------------------------------------------------------------------
1 | [Daml](https://daml.com) is an open-source smart contract language designed to build composable
2 | applications on an abstract ledger model.
3 |
4 | Daml is a high level language that focuses on data privacy and authorization of distributed
5 | applications. These concepts are represented first class in the language.
6 |
7 | By abstracting data privacy and authorization, Daml takes the burden off the programmer to think
8 | about concrete cryptographic primitives and lets her focus on workflow logic.
9 |
10 | Daml is a statically typed functional language.
11 |
12 | The full documentation of Daml can be found here .
13 |
--------------------------------------------------------------------------------
/_includes/header.html:
--------------------------------------------------------------------------------
1 |