How to assign default values in Daml

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
1 Like

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
1 Like