Skip to content
CCPEDIAby Unity Nodes
App Development

How to assign default values in Daml

2 posts293 views2 likesLast activity Aug 2021

  1. DaveOP 1

    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
    
  2. cocreature 1

    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