Need help with error in implementing message in daml docs

-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

module User where

-- MAIN_TEMPLATE_BEGIN
template User with
    username: Party
      following: Party // parseerror ":"
    where
      signatory username
      observer following
  -- MAIN_TEMPLATE_END

    key username: Party
    maintainer key

    -- FOLLOW_BEGIN
    nonconsuming choice Follow: ContractId User with
        userToFollow: Party
      controller username
      do
        assertMsg "You cannot follow yourself" (userToFollow /= username)
        assertMsg "You cannot follow the same user twice" (notElem userToFollow following)
        archive self
        create this with following = userToFollow :: following
    -- FOLLOW_END
          nonconsuming choice SendMessage: ContractId Message with
        sender: Party
        content: Text
      controller sender
      do
        assertMsg "Designated user must follow you back to send a message" (elem sender following)
        create Message with sender, receiver = username, content
     --
template Message with
    sender: Party
    receiver: Party
    content: Text
  where
    signatory sender, receiver

       

Daml is indentation sensitive. There are a few issues here:

  1. You need to align the fields of your template so align following with username
  2. The definitions after where all need to be aligned and indented more than where itself. You can get there by unindenting where and aligning the two nonconsuming.

You also have a type error: following should be a list of parties not a single party.

The fully working version looks like this

-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

module Main where

-- MAIN_TEMPLATE_BEGIN
template User with
    username: Party
    following: [Party]
  where
    signatory username
    observer following
  -- MAIN_TEMPLATE_END

    key username : Party
    maintainer key

    -- FOLLOW_BEGIN
    nonconsuming choice Follow: ContractId User with
        userToFollow: Party
      controller username
      do
        assertMsg "You cannot follow yourself" (userToFollow /= username)
        assertMsg "You cannot follow the same user twice" (notElem userToFollow following)
        archive self
        create this with following = userToFollow :: following
    -- FOLLOW_END
    nonconsuming choice SendMessage: ContractId Message with
        sender: Party
        content: Text
      controller sender
      do
        assertMsg "Designated user must follow you back to send a message" (elem sender following)
        create Message with sender, receiver = username, content
     --
template Message with
    sender: Party
    receiver: Party
    content: Text
  where
    signatory sender, receiver
2 Likes

Thank you so much!

And I have another issue I would like to help on if you have a email?

I still get another error aafter fixing the code.
Property ‘SendMessage’ does not exist on type ‘Template<User, string, “416cf99adf34559ba99cfd9cfddabdbaba0904c5d7ebe0cfd28ac2a9e61252ae:User:User”> & { Archive: Choice<User, Archive, {}, string>; Follow: Choice<…>; }’. TS2339

26 | }
27 | setIsSubmitting(true);

28 | await ledger.exerciseByKey(User.User.SendMessage, receiver, {sender, content});
| ^
29 | setContent(“”);
30 | } catch (error) {
31 | alert(Error sending message:\n${JSON.stringify(error)});

That sounds like you didn’t regenerate your typescript code. You can press r in the daml start window to do so.

Thanks now I got another error :stuck_out_tongue:

TypeScript error in C:/Users/BlockTech4u/Desktop/create-daml-app/ui/src/components/LoginScreen.tsx(8,10):
Module ‘“…/…/…/…/…/…/…/Users/BlockTech4u/Desktop/create-daml-app/ui/daml.js/create-daml-app-0.1.0/lib”’ has no exported member ‘User’. TS2305

 6 | import Credentials, { computeCredentials } from '../Credentials';
 7 | import Ledger from '@daml/ledger';

8 | import { User } from ‘@daml.js/create-daml-app’;
| ^
9 | import { DeploymentMode, deploymentMode, ledgerId, httpBaseUrl} from ‘…/config’;
10 | import { useEffect } from ‘react’;
11 |

Did the codegen run without error? If so you should definitely have the User export. Have you tried restarting VSCode? It may not be seeing the latest version of the files.

DUnno, Have another Isuue that I need help with. in DM or email if u can help out!

Hi @growtogether,

We do not provide private support for the Community Edition, only public support through this forum.

If you need help with issues you are not comfortable discussing on a public platform, please contact our sales team to arrange for an Entreprise Edition license, which would allow you to access private support channels.

Sure how do I do that?

You can send an email to sales@digitalasset.com.

1 Like