I have two scripts, one that allocates the parties on startup, and another that interacts with the ledger at runtime. How can I get a reference to my parties in the second one? If I use allocatePartyWithHint again I get Invalid argument: Party already exists.
The same issue exists I want to interact with a running and initialized ledger using the DAML REPL.
To get a reference to an already existing party you can use the --input-file feature and pass them in externally. That way it is also not hardcoded and you can change the party without having to change your code. To provide a simple example, let’s say you want to pass in a single party. First turn your script into a function:
test : Party -> Script ()
test p = do
submit p $ createCmd …
Next create a JSON file that contains your argument. The format is the same DAML-LF JSON encoding used in the HTTP JSON API so here it is a simple string containing the party:
"Alice"
Now you can pass the path to that JSON file via --input-file and the script will be executed after applying it to the argument.
For daml repl there is no nice option for doing this atm. As a hack you can use partyFromText so something like Some x <- pure $ partyFromText "Alice".
Oh, this is a good hint. Is this an experimental feature? I had the same issue but couldn’t find any explanation in the manual.
It would be even more convenient if there would be a way to get the ListParties result from the party management endpoint. Then the dance with the JSON file wouldn’t be necessary.
--input-file has been there since the first version of DAML Script and is mentioned in the docs at https://docs.daml.com/daml-script/index.html. partyFromText is a bit of a questionable hack so I’m not sure if it is documented.