Skip to content
Discussions/App Development/Is it possible to parse a party name from text in DAML scriptForum ↗

Is it possible to parse a party name from text in DAML script

App Development6 posts744 views5 likesLast activity Mar 2021
SI
simonOP
Mar 2021

The Alice and Bob parties have been created and exist on different Daml-Driver-for-Corda participant nodes and do not currently know about each other.

I want to use Daml script to allow Alice to send a contract to Bob once Bob has shared his party identifier (‘D:bob:O:Tribeca:L:New York:C:US’) with Alice.

The problem is that there appears to be no way to parse a text string into a Party.

CO
cocreature
Mar 2021

Hi @simon,
For most usecases, I would recommend that you accept the parties you intend to reference as an argument instead of hardcoding them in your script. You can then specify those parties via --input-file as described in the documentation. That makes your script easily portable and not dependent on your particular ledger setup and the corresponding party ids.

That said, if you really do want to hardcode the party ids you can use partyFromText : Text -> Optional Party.

GA
Gary_Verhaegen
Mar 2021

I actually wrote a full example that uses partyFromText by reading the parties (as Text) from input files here. I guess what @cocreature means is you could type the inputs as Party directly and thus avoid the call to partyFromText.

CO
cocreature
Mar 2021
Gary_Verhaegen:

I guess what @cocreature means is you could type the inputs as Party directly and thus avoid the call to partyFromText .

Exactly, there is no point calling partyFromText in that case since the JSON encoding of parties is just a string.

SI
simon
Mar 2021

@cocreature / @Gary_Verhaegen - Using an input file works perfectly, many thanks.

SI
simon
Mar 2021

Using an input-file worked great when when I was using a single parameter, when I changed my script to accept three arguments the daml script stopped working:
Screenshot 2021-03-10 at 14.35.25

This is because the input file only populates the first parameter, the solution is ensure that all parameters are structured into a single argument, like:
Screenshot 2021-03-10 at 14.36.42

This way a json array containing the arguments can be used in the input-file.

A better alternative may be use a data structure (like LedgerParties in the example docs)

← Back to Discussions