Why do I get an empty array as a result of a query of a template ID?

Hi, I’m using the @daml/ledger npm library to connect to my daml aplication on Hub. Was able to execute a query of a given template ID but got an error when trying to arhive it. Now everytime I try to query the same template (or any other in my ledger) I get an empty array as a response.
Take into account that using the API endpoint on the Hub seems to work as I get the contract from said template Id

Hi @Mateo_Bossio and welcome to the forum!

The most likely cause of this is that the package id in your query does not match the package id of the contracts on the ledger. A good way to confirm that is that you look at the response you get from your Daml Hub query and get the package id from that and also look at the query sent from your client code (via the network tools of your browser) to see what package id is in there.

Assuming you do have a mismatch, the usual cause of this is that you edited your Daml files after contracts were already created on the ledger (and reran the js codegen). To the ledger, the new package you built locally after making modifications is a completely different one from the one you uploaded before because it has a different package id.

There are a few options to resolve this:

  1. If that was unintentional just revert your changes.
  2. If you’re still in development, just deleting & recreating your ledger and uploading the new package may be the easiest option.
  3. If you want to keep your data and change your templates then you need to do a contract upgrade. Take a look at the documentation for details

Why if I did not change my local Daml files? Is there any reason why after trying to execute a choice on the contract this problem shows up?
Thanks for your time

If your choice archives the contract it won’t show up anymore ofc but then it will also not show up on Hub. Apart from that, I don’t see a case where that would happen.

Have you compared the package ids as I suggested?

The problem was I forgot to delete the @daml.js directory inside the node_modules I think. I ran into another unrelated issue when executing the choice but that was fixed by updating the sdk version and the ledger and types libraries. Thank you so much for your help!

1 Like