The Daml Cheat Sheet Flashcards

Memorize the material in "The Fast Track to Daml", also known as "The Cheat Sheet". https://docs.daml.com/cheat-sheet/ (76 cards)

1
Q

Fill in the blanks:

“Daml is an open-source _ _ _
designed to build composable applications
on an _ _ _.”

A

“… smart contract language
… an abstract ledger model.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Fill in the blanks:

“Daml is a high-level language
that focuses on _ _ and _ of distributed applications.”

A

“… data privacy and authorization …”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or False?

Daml is a statically-typed
functional language?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What Daml concept is this?

A person or legal entity that can create contracts and exercise choices.

A

Party

A built-in data type in Daml.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are four roles that a party can have on a contract?

A
  1. Signatory
  2. Observer
  3. Controller
  4. Maintainer

Roles apply to instances of the Party type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Fill in the blank:

“Contracts are created from blueprints called _.”

A

templates.”

This is the Daml code you write.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Daml templates include what three elements?

A
  1. Contract data
  2. Authorization
  3. Choices
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or false?

Once a contract is created, its data can be changed by a choice.

A

False

Contracts are immutable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Fill in the blanks:

“Every contract is a template instance stored as a _ on the _.”

A

entry on the ledger.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What Daml concept is this?

The action that a party can take on a contract.

A

Choice

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True or False?

Choices can archive the current contract and create a new version of the contract, with updated contract data.

A

True

Contracts are immutable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Fill in the blank:

“A choice can only be exercised by its _”

A

“… controller.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Fill in the blanks:

“A choice contains the authorization of:
1. all of the _ and
2. the _ .

(what two sets of parties?)

A
  1. all of the signatories, and
  2. the controller.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What Daml concept is this?

The database where all contracts are recorded.

A

Ledger

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Daml Assistant command

Create a Daml project

A

daml new <myproject>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Daml Assistant command

Create a Daml/React full stack project

A

daml create-daml-app <TARGET PATH>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Daml Assistant command

Start the IDE

A

daml studio

Launches Visual Studio Code and the Daml extension

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Daml Assistant command

Compile the DAML models into a DAR file

A

daml build

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Daml Assistant command

Launch the sandbox ledger and JSON-API

A

daml start

Also builds the project

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Daml Assistant command

Launch the sandbox ledger

in wall-clock time-mode

A

daml sandbox

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Daml Assistant command

Launch the sandbox ledger

in static time-mode

A

daml sandbox --static-time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Daml Assistant command

Launch the JSON-API server

requires a running ledger

A

daml json-api

--ledger-host localhost --ledger-port 6865 --http-port 7575

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Daml Assistant command

Upload a DAR to the ledger

A

daml ledger upload-dar <mydarfile>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Daml Assistant command

Run the test scripts

in the current project

A

daml test

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
# Daml Assistant command Run the test scripts | in a specific file
`daml test --files MyTests.daml`
26
# Daml Assistant command Run the test scripts | in the current project *and dependencies*
`daml test --all`
27
# Daml Assistant command What is the name of the *project configuration file*?
`daml.yaml`
28
# Daml basics What is the *end-of-line* comment delimiter?
two hyphens | `let i = 1 -- This is a comment`
29
# Daml basics What are the delimiters for *surrounding* comments?
curly brace and hyphen | `{- This is another comment -}`
30
# Daml basics What does *every* Daml file start with?
a module header `module MyModule where` | Module name must be capitalized and match the file name.
31
# Daml types How is the *type* of a *variable* specified? | For example, `myVar` is of type `TypeName`
`myVar : TypeName`
32
# Daml types What four types represent *numbers*?
1. `Int` 2. `Numeric n` 3. `Decimal` 4. `BigNumeric` | `BigNumeric` is not serializable; `Decimal` is `Numeric 10`
33
# Daml types What is the type for *a string of characters*?
`Text`
34
# Daml types What is the type for *True and False values*?
`Bool`
35
# Daml types What is the type for *a person or entity* involved in a contract?
`Party`
36
# Daml types What are the three *date and time* types?
1. `Date` 2. `Time` 3. `RelTime`
37
# Daml types Define a *type synonym*. | For example, `MyInt` is a synonym for `Int`
`type MyInt = Int`
38
# Daml types Define a *type synonym for a list*. | For example, a list of `Int`s.
`type ListOfInts = [Int]`
39
# Daml types Define a *type synonym for a tuple*. | For example, a tuple of an `Int` and `Text`
`type MyTuple = (Int, Text)`
40
# Daml types Define a *polymorphic type*. | For example, a list of tuples of types `a` and `b`
`type MyType a b = [(a, b)]`
41
# Daml data What is the *keyword* used to define record, product, and sum types?
`data`
42
# Daml data Define a record. | For example, for an `Int` and `Text`
``` data MyRecord = MyRecord { label1: Int, label2: Text } ``` | fields must have lower-case labels
43
# Daml data Define a product type. | For example, for an `Int` and `Text`
``` data IntAndText = IntAndText with label1:Int label2:Text ```
44
# Daml data Define a sum type. | For example, for an `Int` or `Text`
``` data IntOrText = MyInt Int | MyText Text ``` | case names must be upper case
45
# Daml data Define a record with type parameters. | AKA: "generic" or "polymorphic" record.
``` data MyRecord a b = MyRecord { label1: a, label2: b } ```
46
# Daml data Define a record with Show/Eq instances.
``` data MyRecord = MyRecord { label1: Int, label2: Text } deriving (Show, Eq) ```
47
# Daml functions Specify a function signature. | For example, a function takes two `Text` arguments and returns `Text`
`f : Text -> Text -> Text`
48
# Daml functions Define a function. | For example, concatenate two strings with a space
`f x y = x <> " " <> y`
49
# Daml functions Define a lambda. | For example, concatenate two strings
`\x y -> x <> y`
50
# Daml functions In this polymorphic function signature, what does the `=>` follow? | `f : (Show a, Eq a) => a -> Text -> Text`
The type constraints | on the type parameter `a`
51
# Daml functions Apply a function. | For example, `f : Text -> Text -> Text`
`f "Hello" "World"` | "Hello World"
52
# Daml functions Partially apply a function. | For example, `f : Text -> Text -> Text`
salute = f "Hello" | salute : Text -> Text
53
# Daml functions Specify a function signature with a *function* as an argument. | For example, `apply salute "John" -- "Hello John"`
`apply : (Text -> Text) -> Text -> Text`
54
# Daml templates What is the keyword for beginning the blueprint of a contract?
`template` ``` template MyData with party : Party where signatory party ```
55
# Daml templates What is the keyword for listing the data that will be stored?
`with` ``` template MyData with party : Party where signatory party ```
56
# Daml templates What is the keyword for listing visibility, roles, choices?
`where` ``` template MyData with party : Party where signatory party ```
57
# Daml templates What keyword identifies the party authorizing the contract?
`signatory` ``` where signatory party1 ```
58
# Daml templates What keyword identifies a party with visibility to the contract?
`observer` ``` where observer party2 ```
59
# Daml templates What keyword specifies a primary index for the contract?
`key` ``` where key dataKey : (Party, Text) ```
60
# Daml templates What keyword identies a party guaranteeing uniqueness of contract keys?
`maintainer` ``` where maintainer key._1 ```
61
# Contract keys When a contract is updated, what identifier changes and what identifier stays the same?
_Contract keys_ stay the same. _Contract ids_ change.
62
# True or False? Contract keys on a template are optional.
True
63
# True or False? Contract keys can be specified without a maintainer.
False
64
# True or False? The contract key must _not_ include a contract id.
True
65
# True or False? The contract key _must_ include all maintainer parties.
True
66
# True or False? The choices of a contract template specify the rules on how and by whom contract data can be changed.
True
67
# Daml choices If a choice is "consuming" what does that imply?
Trying to exercise another choice on the same contract id will fail.
68
# Daml choices If a choice is "nonconsuming" what does that imply?
More choices can be subsequently exercised.
69
# Daml choices Choices are *what* by default? | Consuming or nonconsuming?
Consuming
70
# Daml choices What is the keyword for defining an action that can be exercised on a contract?
`choice` ``` where nonconsuming choice NameOfChoice : () with ```
71
# Daml choices What is the keyword for listing the choice arguments?
`with` ``` nonconsuming choice NameOfChoice : () with party1 : Party party2 : Party ```
72
# Daml choices What is the keyword for listing the parties that are required to execute a choice?
`controller` ``` nonconsuming choice NameOfChoice : () with party : Party controller party do ``` |
73
# Daml choices What is the keyword for the block of code that executes?
`do` ``` controller party do assert (i == 42) return () ```
74
# Daml updates Where are *update* expressions listed? | Choices or scripts?
In a choice body | Usually along with other expressions in a `do` block
75
# Daml updates What is the *update expression* to create an instance of the given template on the ledger? | For example, `NameOfTemplate` and `exampleParameter` inputs
`create NameOfTemplate with exampleParameters`
76
# Daml updates What is the *update expression* to exercise a choice on a given contract by contract id? | For example, `idOfContract`, `NameOfChoice`, `choiceArgument1 = value1`
`exercise idOfContract NameOfChoice with choiceArgument1 = value1`