Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/How to assign default values in DamlForum ↗

How to assign default values in Daml

App Development2 posts268 views2 likesLast activity Aug 2021
DA
DaveOP
Aug 2021

I’m trying to work out how to assign a default value in Daml. I came across this stackoverflow answer and can’t understand why I’m getting the error ‘parse error on input ‘0.00’’ under the '0.00. My code:

template ChildInvite
    with
        parent : Party
        child : Party
    where
        signatory parent

        controller child can
            AcceptInvite : ContractId Child
                with
                    parent : parent
                    child : child
                    money : 0.00
CO
cocreature
Aug 2021

x : y is a type annotation specifying that x has type y. So in your example you’re specifying that money has type 0.0 which is an error since 0.0 is a value of type Decimal but not a type itself.

More generally with on a choice specifies the choice argument fields and their types but I believe you don’t actually want any arguments to that choice, you want to create a Child (hello frankenstein) and set the fields to the given values. For that, try something like the following:

template ChildInvite
    with
        parent : Party
        child : Party
    where
        signatory parent

        controller child can
            AcceptInvite : ContractId Child
              do create Child with
                    parent = parent
                    child = child
                    money = 0.00
← Back to Discussions