Contract Key not found when submitting commands to json api via Java

Good afternoon all,

I’m attempting to write a little java app to submit commands to the json api, and I’m having a little issue with contract keys. When the key has multiple parts (e.g. (Party, Text)) it returns that the key cannot be found, although contracts where the key is just Party do work fine.

I’m creating the key in a HashMap and converting the command to json using Jackson. It seems to match the example on the docs page, so I’m not certain what’s going wrong. Below is an example of the command I’m trying to submit:

{
    "templateId":"Main:SecondContract",
    "key":{"_1":"Alice","_2":"Bob","_3":"c372cb5a-7b70-4f61-82b3-9dd776d63c22"},
    "choice":"FourthUpdateTest",
    "argument":{"thirdID":"204978a1-6693-46d2-b244-c8832d826ccc","fourthID":"e99f96d8-f857-47c5-8b76-2da6011f8b8f"}
}
2 Likes

Hi @lashenhurst, I don’t see anything off with the query. If you query for Main:SecondContract contracts, do you see a contract with the given key? Maybe it’s just archived or not visible to your party?

1 Like

I do see the contract when I query for it, it’s definitely active and visible to my Party.

Could it be that it’s not the contract that you are exercising the choice on that is not found but that the choice references some other contracts by keys (by calling fetchByKey, lookupByKey or exerciseByKey) and those are not active? It’s a bit hard to see from your example but maybe thirdID and fourthID are used as keys that you lookup later?

If possible, it would be great if you could share some of your DAML code and the full error you are receiving.

That’s it, it was a little exerciseByKey at the end of the choice. Thank you!

I wish it was easier to determine whether the command failed because of the contract being referenced or the logic inside the choice.

1 Like

Fully agree, we’ll see if we can make it a bit clearer which part failed.

1 Like

Thanks for the suggestion @lashenhurst, and welcome to the DAML community!