When do I need to submit the package ID as part of the template id for JSON API transactions?

Sometimes I have to specify the template id for JSON API transactions in the full format, if I fail to submit the package id, I get an error message:

<package ID>:<module name>:<template name>

Sometimes the short version is enough:

<module name>:<template name>

wich is described in the documentation (HTTP Request).

What makes the difference?

If I have to submit the package id, what is the easiest way to get it?


You have to submit the package id if the pair (moduleName, templateName) is not unique among all DAML-LF packages uploaded to the ledger. I would generally recommend that you always include the package id for production applications but for testing and debugging it’s of course totally fine to omit it.

As for getting access to the package id, if you can I would recommend to use the JavaScript codegen which will automatically include this on all requests. If that is not an option for whatever reason, you can use daml damlc inspect-jar --json .daml/dist/mydar.dar to print out the package id. The main_package_id in there is the one of your current project but you also get the package id of your dependencies. If you want to extract it automatically, something like jq or your favorite JSON library will do the job.


Thank you!

2 posts were split to a new topic: How do you deal with multiple DAR files with the same template name on a ledger?

What if the daml build and daml deploy commands returned the main package id?

1 Like

I prefer having it in a separate command with machine-readable output as opposed to trying to add more output to a command that does not produce machine readable output. That just means people will start relying on the current output format of daml build and parse it via grep or whatever else which is guaranteed to break at some point.