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/

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

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

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

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
Q

Daml Assistant command

Run the test scripts

in a specific file

A

daml test --files MyTests.daml

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

Daml Assistant command

Run the test scripts

in the current project and dependencies

A

daml test --all

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

Daml Assistant command

What is the name of the project configuration file?

A

daml.yaml

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

Daml basics

What is the end-of-line comment delimiter?

A

two hyphens

let i = 1 -- This is a comment

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

Daml basics

What are the delimiters for surrounding comments?

A

curly brace and hyphen

{- This is another comment -}

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

Daml basics

What does every Daml file start with?

A

a module header

module MyModule where

Module name must be capitalized and match the file name.

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

Daml types

How is the type of a variable specified?

For example, myVar is of type TypeName

A

myVar : TypeName

32
Q

Daml types

What four types represent numbers?

A
  1. Int
  2. Numeric n
  3. Decimal
  4. BigNumeric

BigNumeric is not serializable; Decimal is Numeric 10

33
Q

Daml types

What is the type for a string of characters?

A

Text

34
Q

Daml types

What is the type for True and False values?

A

Bool

35
Q

Daml types

What is the type for a person or entity involved in a contract?

A

Party

36
Q

Daml types

What are the three date and time types?

A
  1. Date
  2. Time
  3. RelTime
37
Q

Daml types

Define a type synonym.

For example, MyInt is a synonym for Int

A

type MyInt = Int

38
Q

Daml types

Define a type synonym for a list.

For example, a list of Ints.

A

type ListOfInts = [Int]

39
Q

Daml types

Define a type synonym for a tuple.

For example, a tuple of an Int and Text

A

type MyTuple = (Int, Text)

40
Q

Daml types

Define a polymorphic type.

For example, a list of tuples of types a and b

A

type MyType a b = [(a, b)]

41
Q

Daml data

What is the keyword used to define record, product, and sum types?

A

data

42
Q

Daml data

Define a record.

For example, for an Int and Text

A
data MyRecord = MyRecord {
  label1: Int,
  label2: Text
}

fields must have lower-case labels

43
Q

Daml data

Define a product type.

For example, for an Int and Text

A
data IntAndText = IntAndText
    with label1:Int
         label2:Text
44
Q

Daml data

Define a sum type.

For example, for an Int or Text

A
data IntOrText = MyInt Int | MyText Text

case names must be upper case

45
Q

Daml data

Define a record with type parameters.

AKA: “generic” or “polymorphic” record.

A
data MyRecord a b = MyRecord {
  label1: a,
  label2: b
}
46
Q

Daml data

Define a record with Show/Eq instances.

A
data MyRecord = MyRecord {
  label1: Int,
  label2: Text
} deriving (Show, Eq)
47
Q

Daml functions

Specify a function signature.

For example, a function takes two Text arguments and returns Text

A

f : Text -> Text -> Text

48
Q

Daml functions

Define a function.

For example, concatenate two strings with a space

A

f x y = x <> " " <> y

49
Q

Daml functions

Define a lambda.

For example, concatenate two strings

A

\x y -> x <> y

50
Q

Daml functions

In this polymorphic function signature, what does the => follow?

f : (Show a, Eq a) => a -> Text -> Text

A

The type constraints

on the type parameter a

51
Q

Daml functions

Apply a function.

For example, f : Text -> Text -> Text

A

f "Hello" "World"

“Hello World”

52
Q

Daml functions

Partially apply a function.

For example, f : Text -> Text -> Text

A

salute = f “Hello”

salute : Text -> Text

53
Q

Daml functions

Specify a function signature with a function as an argument.

For example, apply salute "John" -- "Hello John"

A

apply : (Text -> Text) -> Text -> Text

54
Q

Daml templates

What is the keyword for beginning the blueprint of a contract?

A

template

template MyData
  with
    party : Party
  where
    signatory party
55
Q

Daml templates

What is the keyword for listing the data that will be stored?

A

with

template MyData
  with
    party : Party
  where
    signatory party
56
Q

Daml templates

What is the keyword for listing visibility, roles, choices?

A

where

template MyData
  with
    party : Party
  where
    signatory party
57
Q

Daml templates

What keyword identifies the party authorizing the contract?

A

signatory

  where
    signatory party1
58
Q

Daml templates

What keyword identifies a party with visibility to the contract?

A

observer

  where
    observer  party2
59
Q

Daml templates

What keyword specifies a primary index for the contract?

A

key

  where
    key dataKey : (Party, Text)
60
Q

Daml templates

What keyword identies a party guaranteeing uniqueness of contract keys?

A

maintainer

  where
    maintainer key._1
61
Q

Contract keys

When a contract is updated, what identifier changes and what identifier stays the same?

A

Contract keys stay the same.
Contract ids change.

62
Q

True or False?

Contract keys on a template are optional.

A

True

63
Q

True or False?

Contract keys can be specified without a maintainer.

A

False

64
Q

True or False?

The contract key must not include a contract id.

A

True

65
Q

True or False?

The contract key must include all maintainer parties.

A

True

66
Q

True or False?

The choices of a contract template specify the rules on how and by whom contract data can be changed.

A

True

67
Q

Daml choices

If a choice is “consuming” what does that imply?

A

Trying to exercise another choice on the same contract id will fail.

68
Q

Daml choices

If a choice is “nonconsuming” what does that imply?

A

More choices can be subsequently exercised.

69
Q

Daml choices

Choices are what by default?

Consuming or nonconsuming?

A

Consuming

70
Q

Daml choices

What is the keyword for defining an action that can be exercised on a contract?

A

choice

where
  nonconsuming choice NameOfChoice : ()
    with
71
Q

Daml choices

What is the keyword for listing the choice arguments?

A

with

nonconsuming choice NameOfChoice : ()
  with
    party1 : Party
    party2 : Party
72
Q

Daml choices

What is the keyword for listing the parties that are required to execute a choice?

A

controller

nonconsuming choice NameOfChoice : ()
  with
    party : Party
  controller party
    do

|

73
Q

Daml choices

What is the keyword for the block of code that executes?

A

do

controller party
    do
      assert (i == 42)
      return ()
74
Q

Daml updates

Where are update expressions listed?

Choices or scripts?

A

In a choice body

Usually along with other expressions in a do block

75
Q

Daml updates

What is the update expression to create an instance of the given template on the ledger?

For example, NameOfTemplate and exampleParameter inputs

A

create NameOfTemplate with exampleParameters

76
Q

Daml updates

What is the update expression to exercise a choice on a given contract by contract id?

For example, idOfContract, NameOfChoice, choiceArgument1 = value1

A

exercise idOfContract NameOfChoice with choiceArgument1 = value1