How do I get the current active contract set over the JSON API with the JS daml ledger bindings?

I expected the below to work as the docs say that if I submit an empty query I’ll get back the active contract set but if I don’t give query() an object I get back an error:

import Ledger from '@daml/ledger';
var ledger = new Ledger({token, ledgerUrl, reconnectThreshold: 60});
var activeContractSet = ledger.query();

Which results in the error:

TypeError: Cannot read property 'templateId' of undefined

Same if I use an empty object as in:

var activeContractSet = ledger.query({});

Which results in the error:

"JsonReaderError. Cannot read JSON: <{"templateIds":[null]}>. Cause: spray.json.DeserializationException: Expected JsString([<packageId>:]<module>:<entity>), got: null"

Hi @anthony, the JS bindings always operate on a specific template. If you look at the documentation you can see that the first parameter, i.e., the template is mandatory and only the query argument is optional. The template argument should be the one that gets generated by the JS codegen. There is currently no way to query contracts of all templates. While the JSON API does provide that functionality (via the GET request to /v1/query), it also suffers from performance issues there so even if you use that, I’d recommend querying for specific templates instead.

1 Like