Indentation sensitivity, case sensitivity, and field names vs variable names

I’ve been following the tutorials on the proposal accept pattern. I want to implement a situation with my smart contract where a person can create a guild that has multiple members.

So I setup the following template

template Guild with
    guildname: Text
    creator: Party
    member: [Party]
  where
    signatory creator
    ensure length member >= 5 && DA.List.unique member


template Individual with
    person: Party
    name: Text
    guild: Guild
  where
    signatory person

    controller person can
      CreateGuild : ContractId Guild
        do
          create guild

and then the following script to test.

-- RUN_GUILD_TEST SCRIPT

guildtest = do
  martin <- allocateParty "Martin"
  rita <- allocateParty "Rita"
  john <- allocateParty "John"
  michael <- allocateParty "Michael"
  sam <- allocateParty "Sam"
  james <- allocateparty "James"

let
    guild = Guild with
      guildname = "Ahi"
      creator = martin
      member = [rita, john, michael, sam, james]

guildCid <- submit martin do
    createCmd Individual
      with
        person = martin
        name: "Martin"
        guild: Guild
submit martin do
    exerciseCmd individualCid CreateGuild
pure()

I’m getting a parser error on the line that starts with “guildCid”.

(obligatory screenshot)

I’m not sure what I am doing wrong?
Martin should have the authorisation to create this contract. And I am calling the Guild contract ID. I don’t believe this is an indentation error.

Unless I am setting up this pattern the wrong way round?
A person can form a guild . I don’t want the guild to form the person.

Some guidance please?

1 Like

Daml is indentation sensitive, all statements in a do block need to start at the same line. So indent the let, indent guildCid and indent the submit. There are a few other minor typos:

  1. allocateParty not allocateparty
  2. name = "Martin" not name: "Martin"
  3. guild = guild not guild: Guild
  4. individualCid does not exist, I assume you mean guildCid created above.

Putting all things above, the following script should do the trick:

guildtest = do
  martin <- allocateParty "Martin"
  rita <- allocateParty "Rita"
  john <- allocateParty "John"
  michael <- allocateParty "Michael"
  sam <- allocateParty "Sam"
  james <- allocateParty "James"

  let
    guild = Guild with
      guildname = "Ahi"
      creator = martin
      member = [rita, john, michael, sam, james]

  guildCid <- submit martin do
    createCmd Individual
      with
        person = martin
        name = "Martin"
        guild = guild
  submit martin do
    exerciseCmd guildCid CreateGuild
  pure()
1 Like

Thank you so much @cocreature, it is working, but why does guild = guild ? Is it because I am calling guild from the second line after the let statement?

1 Like

guid = guild assigns the field called guild of the Individual you are created to the variable called guild which you are defining in the let above. There is actually also a shorthand for this, you can just write guild instead of guild = guild or use .. to fill in all fields not set otherwise that way.

First option:

  guildCid <- submit martin do
    createCmd Individual
      with
        person = martin
        name = "Martin"
        guild

Second option

guildCid <- submit martin do
    createCmd Individual
      with
        person = martin
        name = "Martin"
        ..
2 Likes

A post was split to a new topic: Variable not in scope: submitMulti