Contract creation in JSON API

Hello Daml Community,

I am trying to create a contract via JSON API,

I set up my jwt token:

And i get my party id by running the following command:

daml script --dar .daml/dist/script-example-0.0.1.dar --script-name ScriptExample:allocateParties --ledger-host localhost --ledger-port 6865 --output-file ledger-parties.json

Ledger-parties.json:

Still when i try to create a contract i get this error:

Any clue? Thank you

You have three different party ids being used here that look like they are all supposed to refer to the same party. That mismatch results in the authorization error. Specifically, you have the following three:

  1. Your token is for party Alice::…
  2. If you look at the error message you can see that it’s referring to Alice without any suffix. This probably comes from one of your contract payload that you’re sending to the JSON API containing that. Try changing that to match your token, i.e., Alice::….
  3. Lastly, the script file you showed uses party-…::… instead of Alice::…. I don’t really know how you got to that mismatch. Where did you get the one that is part of the token?

Hello cocreature, thanks for the answer,

I understood what i got wrong, and i already create a contract with JSON API,

First my partyid was wrong, i got it from navigator:

ALICE: party-cf4ce109-c007-45d7-839e-2f7756e5e5de::1220124aba0791c61bac337ed9319ce99bf9e96259acb554c2fbb244d20155bcfc95

BOB: party-660bf503-c37d-4aca-88ed-b2df54d1e940::1220124aba0791c61bac337ed9319ce99bf9e96259acb554c2fbb244d20155bcfc95

I fill out asker with partyid ALICE and answerer with partyid BOB,
This means that when i create a contract i have to use these ids for each fiel.

How can i get a partyid like your example Alice::… and Bob::… ?
Like: Alice::1220124aba0791c61bac337ed9319ce99bf9e96259acb554c2fbb244d20155bcfc95 ?

When i run this command why dont i get the same partyids as the navigator?

daml script --dar .daml/dist/script-example-0.0.1.dar --script-name ScriptExample:allocateParties --ledger-host localhost --ledger-port 6865 --output-file ledger-parties.json

LINK:
https://docs.daml.com/daml-script/index.html?_ga=2.73706902.544579627.1652783421-1662226590.1652783421#run-a-script

Ledger-parties.json file:


(the first part of the partyid is different from the navigator but the second part is equal)

If it helps here are my daml files:
daml.yaml
image

Lights.daml


image

allocateParty creates a new party everytime you run it. So if you run your Daml Script multiple times you get different parties each time which sounds like that’s what’s been happening here: You’ve run it once via initializeUser and then once via allocateParties directly. I recommend to have initializeUser return LedgerParties and then only run that once. If you run it via daml start, you can set the --output-file flag via daml start --script-option --output-file=parties.json.

For the Alice::… part, you can allocate such parties via allocatePartyWithHint … (PartyIdHint "Alice"). The hint will be used as a prefix.

2 Likes

Thanks cocreature, I did what you suggested and it worked!