How to get package_id for submit_command with gRPC

Hi team,

I am working on setting up a gRPC client to call the Daml ledger api from a Rails app. Following the Java example here: https://github.com/digital-asset/ex-java-bindings/blob/89052898bbdf9828f08ea039c87095bf65bf679b/README.rst#setting-up-the-example-projects
In the Java example above, it seems like the package.id is set during build time, instead of runtime.

The application I am working on consists of multiple packages (and sometimes just 1 when running sandbox in local dev), so I am wondering if there’s a possible way to get the package.Id during runtime from Ledger Api.
https://docs.daml.com/app-dev/grpc/proto-docs.html#com-daml-ledger-api-v1-identifier

I am trying to get it from PackageManagementService ListKnownPackages, but it doesn’t provide package-name in the details. I do see the package_id that I am looking for and its source_description: '', so I am wondering if I can set the source_description to the package_name which would help me identify the package_id.

The only recommended way I see online is using daml damlc inspect-dar with jq, but it doesn’t sound right to be doing that during runtime.

Thank you,

There’s no real safe way of doing that on a shared ledger. Imagine you uploaded a package Foo and someone else also uploaded a malicious package Foo. If you just look for some package Foo at runtime, you run the risk of accidentally picking up the wrong one.

If you have full control of the Participant node and can thus make sure there is only one such, you can do this:

Use the PackageService to first list all package Ids using ListPackages, then fetch each package using GetPackage and deserialize them until you find one that matches what you are looking for.

The deserialization is demonstrated using JavaScript here.

1 Like

How does Json-Api get the package_id to pass to ledger api? I never had to input package_id it was always just template. Some insights on this would be helpful, thanks!

Else I think the easiest approach for me right now is to setup a Database table for package_name package_id mapping and populate it when I upload those packages.

It does exactly what I described above. It maintains a cache of all packages and identifiers so it can locally resolve requests to an appropriate PackageId if none are supplied.

Got it, thanks