How to get package_id for submit_command with gRPC
- wilsonhsu0102OP
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 thepackage.idis 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.Idduring runtime from Ledger Api.
https://docs.daml.com/app-dev/grpc/proto-docs.html#com-daml-ledger-api-v1-identifierI am trying to get it from
PackageManagementServiceListKnownPackages, but it doesn’t providepackage-namein the details. I do see thepackage_idthat I am looking for and itssource_description: '', so I am wondering if I can set thesource_descriptionto thepackage_namewhich would help me identify thepackage_id.The only recommended way I see online is using
daml damlc inspect-darwithjq, but it doesn’t sound right to be doing that during runtime.Thank you,
- bernhard 1
There’s no real safe way of doing that on a shared ledger. Imagine you uploaded a package
Fooand someone else also uploaded a malicious packageFoo. If you just look for some packageFooat 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 usingGetPackageand deserialize them until you find one that matches what you are looking for.The deserialization is demonstrated using JavaScript here.
- wilsonhsu0102
How does Json-Api get the
package_idto pass to ledger api? I never had to inputpackage_idit was always justtemplate. 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_namepackage_idmapping and populate it when I upload those packages. - bernhard
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.
- wilsonhsu0102
Got it, thanks