What is the use of packageService and what is meant by packageId?

When we start the sandbox, a list of package IDs are printing in console. What is that and where we use that?

1 Like

A package in this context is a unit of compiled DAML code. In a way, ignoring a lot of cool features, DAML is a remote procedure call system: you write your DAML code, compile it, and then send it to a DAML engine, and then your users can execute said DAML code through an API. Users need to tell the engine exactly what code they wish to execute, and they use the package ID to do so.

When you compile a DAML project, the result is a DAR file. A DAR file is a ZIP file that contains a number of DALF files (+ some metadata). A DALF file is a package and contains compiled DAML code, called DAML-LF. Each package has a package ID, which you can think of as a hash of the DALF file, so two packages with the exact same code in them have the same ID.

When referenced through the API, DAML code is generally addressed as <package ID>:<module name>:<binding>, so you know exactly what code you’re executing.

Finally, the PackageService is the part of the gRPC Ledger API that lets you ask a ledger what packages it currently knows, i.e. what code other people (or past you) have uploaded.

More information about packages can be found here.

1 Like