How to create templates using UserAdmin Party

This is a follow up to alex_matson’s reply regarding UserAdmin parties

How do I grab the user admin party without hardcoding it? Right now I need to go to the damlhub GUI, and click on userAdmin to see the ledger party, but I don’t want to / don’t need to be hardcoding that.

Also, how can I create contracts on behalf of the userAdmin when the app is deployed on DamlHub? Right now I login with my email, and I’m assigned a ledger party ID, but how can I login with the userAdmin?
I need to have some templates where the issuer is the userAdmin.

How do I configure the trigger for Daml hub? Right now I run locally, where I specify the party?

             --trigger-name Trigger:autoSendExampleAssetAccountProposal \
             --ledger-host localhost \
             --ledger-port 6865 \
             --ledger-party a

EDIT:
No longer need a solution on deploying Daml trigger, just needed to upload the Dar file, and the Daml Hub UI will have an extra step for the triggers

[quote=“Max, post:1, topic:4266, full:true”]
This is a follow up to alex_matson’s reply regarding UserAdmin parties

How do I grab the user admin party without hardcoding it? Right now I need to go to the damlhub GUI, and click on userAdmin to see the ledger party, but I don’t want to / don’t need to be hardcoding that.

Also, how can I create contracts on behalf of the userAdmin when the app is deployed on DamlHub? Right now I login with my email, and I’m assigned a ledger party ID, but how can I login with the userAdmin?
I need to have some templates where the issuer is the userAdmin.

Edit:
No longer need solution for deploying as party on Daml Hub, just had to upload the dar, and daml hub will show a separate screen for triggers.

How do I configure the trigger for Daml hub? Right now I run locally, where I specify the party?

             --trigger-name Trigger:autoSendExampleAssetAccountProposal \
             --ledger-host localhost \
             --ledger-port 6865 \
             --ledger-party a

EDIT:
No longer need a solution for deploying daml trigger. Just needed to upload the dar file, and daml hub will give extra step for triggers.

I’m trying to understand the docs here https://hub.daml.com/docs/api/
But I can’t seem to find explicit steps on running the trigger as a party, or perhaps I’m simply not understanding how to deploy the trigger on daml hub. The instructions just say deploy the daml trigger along with your Dar, but when I build the Dar file I don’t see a separate trigger dar file

I’ll answer the questions here in sections -

Trigger Dar Building

The instructions just say deploy the daml trigger along with your Dar, but when I build the Dar file I don’t see a separate trigger dar file

The separate trigger dar has to be built separately. I think the current docs are lacking some clarity on this, but the idea is you should organize your code & project such that the triggers are written as a separate Daml project. The da-marketplace app is a great example to look at: The triggers are placed in a triggers/ subdirectory with their own daml.yaml file: https://github.com/digital-asset/da-marketplace/tree/main/triggers. The trigger’s daml.yaml then references the main dar as a data-dependency, which allows you to use those templates in your trigger code.

When split like this, you’ll run a daml build from the root for the main dar file and a daml build inside triggers to create the triggers dar file. Both dars are then uploaded to your Daml Hub ledger.

Trigger Deployment

There are two ways to deploy a trigger on Daml Hub: you can do so manually via the web console (see screenshot) or programmatically via the published automations API. I suggest standing up a working end-to-end deployment of your application (including triggers) via the web console first, and think about automation later. This will help build an intuition on how all the pieces operate in a Hub world.

Because a trigger dar may contain multiple triggers, you select the trigger name and the party whose authority the trigger will run under.

User Admin

The User Admin party ID is publicly discoverable. Daml Hub exposes a Default Parties API that allows your application to discover the party IDs for the User Admin and Public parties.

Log In

To enable your UI to allow you to log in as parties other than your personal party (including UserAdmin), the easiest approach is to simply add a form to the login screen where a JWT token can be pasted in. @daml/hub-react can help here, by using the DamlHubLogin component with the withToken prop:

<DamlHubLogin withToken onLogin={(credential, error) => {
  if (credential) {
    /* handle credentials. the application may cache the token and use it for subsequent API calls. */
    const { party, token } = credential;
    console.log(party, token);
  }
  else { /* handle error */  }
}}>

With this in place, you can copy the UserAdmin JWT from the Identities page and use it to log in.

Hi Alex,
Thanks for the detailed response! Okay, so triggers as a separate directory all together. I’m all clear on that now.

Trigger Deployment
I’ve deployed it via the web console

Log in
Right now when we log in on Damlhub, we go through the built-in Auth0 where I login with an email. So what it looks like is that I’ll need to use the @daml/hub-react on top of the @daml/react library too for a separate login method where I paste the JWT into the form right?

Let me try that.

@Alex_Matson
How do I set up a separate daml project within my current daml project?
I’m trying to manually create a triggers directory, and adding the daml.yaml file, and creating a daml directory with my trigger. However, I get

Could not find module `Daml.Trigger'
It is not a module in the current program, or in any known package.

My main daml file with the templates are one directory above. My daml.yaml file in the trigger directory is specified as below, mainly copy and paste, just changed the sdk version and the data-dep

sdk-version: 1.18.1
name: wallet-refapp-triggers
source: daml
parties:
  - Alice
  - Bob
  - Operator
  - Custodian
  - BtcIssuer
  - UsdtIssuer
  - Public
  - Exchange
  - Broker
  - Ccp
version: 0.1.0
# trigger-dependencies-begin
dependencies:
  - daml-prim
  - daml-stdlib
  - daml-trigger
data-dependencies:
  - ../.daml/dist/wallet-refapp-0.1.0.dar
sandbox-options:
  - --wall-clock-time
build-options:
  - --ghc-option=-Wno-deprecations
module Trigger where

import Account
import qualified Daml.Trigger as T
import DA.Foldable
import DA.Action
import DA.List (head)

autoSendExampleAssetAccountProposal: T.Trigger ()
autoSendExampleAssetAccountProposal = T.Trigger 
 { initialize = pure (),
  updateState = \_  -> pure (),
  registeredTemplates = T.RegisteredTemplates [T.registeredTemplate @AssetHoldingAccountRequest, T.registeredTemplate @AssetHoldingAccount],
  rule = \p -> do
    asset_holding_account_requests <- T.query @AssetHoldingAccountRequest
    let isNotMe = (\requests -> requests.recipient /= p)
    let notMeList = filter (\(_, contract) -> isNotMe contract) asset_holding_account_requests
    let requests = map fst notMeList


    debug ("requests",requests)
    assetAccounts <- T.query @AssetHoldingAccount
    debug ("assetAccounts", assetAccounts)
    let isET = (\account -> account.assetType.symbol == "ET" && account.assetType.issuer == p)
    let etAccounts = filter (\(_, contract) -> isET contract) assetAccounts
    let cids = map fst etAccounts
    
    
    unless ( DA.Foldable.null requests && DA.Foldable.null cids ) do
      let (cid, c) = head etAccounts

      mapA_(\request -> T.dedupExercise request Accept with assetHoldingAccount = cid)  requests
      pure()
    debug $ "TRIGGERED",
  heartbeat = None
}

Was able to finally import another module. My issue was

I started the repo using create-daml-app, and the repo itself was a daml project
So when I tried to do daml new triggers within this repo, I wasn’t able to create a daml project within the daml project.

What I did to resolve it
Create a new directory, move the entire create-daml-app into that repo.

  • at the parent level directory, daml new triggers to create another daml project.

I had a lot of trouble trying to link up the dependencies properly but these sources helped:
starting two separate daml projects in one repo

Importing templates into another module

Import choices from a template to another module

Hey @Max -

I’m glad you got everything working. It’s not clear to me why it wasn’t working the way you had it set up initially with that daml.yaml file, as it looked correct from what I could see. In the future with those kinds of issues it might help to run daml clean in both your root and trigger directories, then rebuilding both (starting with the root project).

1 Like