Given a participants.json from project:DABL, how do I get my party in Daml Script?

I’ve downloaded the participants.json from DABL, which contains something akin to what’s shown in https://docs.daml.com/daml-script/index.html#using-daml-script-in-distributed-topologies.

      "party_participants": {
        "ledger-party-abc123": "bernhard",
        "public-ledgerid": "public"
    }

However, there are dozens and dozens of other parties on my ledger. All have displayName=party and all have isLocal=True.

Is there any way in Daml Script to get my hands on my ledger party without passing in its Party Id or hardcoding it in my script?

1 Like

On most ledgers you can call listKnownParties and then get the party with the given display name (note that uniqueness of display names is not guaranteed by the ledger so you have to ensure that yourself). However, DABL does not (yet) implement that endpoint I believe so this unfortunately doesn’t work.

This leaves passing the party id in from the outside as your only option. Assuming the participant names in the config generated by DABL correspond to display names, you could use jq to go from participants.json to a map of display names to party ids:

> echo '{"party_participants": {"a-id": "a", "b-id": "b"}}' | jq ".party_participants | to_entries | map( {(.value) : .key } ) | add"
{
  "a": "a-id",
  "b": "b-id"
}

You can then use a TextMap Party as the input your DAML Script and index that by display name to get the corresponding party id.