When a Daml project is compiled, it produces a DAR (extensionDocumentation Index
Fetch the complete documentation index at: https://docs.canton.network/llms.txt
Use this file to discover all available pages before exploring further.
.dar), short for Daml Archive. The Daml compiler exposes commands for inspecting this archive.
Inspecting a DAR file
You can rundpm damlc inspect-dar /path/to/your.dar to get a human-readable listing of the files inside it and a list of packages and their package ids. This is often useful to find the package id of the project you just built.
For example, consider a package mypkg which depends on a package dep:
mypkg-1.0.0 is compiled to a DAR, we can inspect that DAR to ensure that it contains both the mypkg package and its dependency dep:
Inspecting a DAR file as JSON
In addition to the human-readable output, you can also get the output as JSON. This is easier to consume programmatically and it is more robust to changes across SDK versions:name and version will be null for packages in Daml-LF < 1.8.
Inspecting the main package of a DAR file
If you’d like to inspect the code inside the main package of a DAR, the Daml compiler provides theinspect tool; running dpm damlc inspect <path-to-dar-file> prints all of the code in the main package of that DAR file in a human-readable format.
For example, run the inspect tool on the DAR produced in the previous section:
Inspecting a DALF file
Theinspect tool also accepts DALF files; running dpm damlc inspect <path-to-dalf-file> on a DALF file prints all of the code in that DALF file.
We can unzip a DAR to access its dalfs and inspect them, for example with the DAR from the previous section:
inspect directly on the DAR file would require fewer steps.
Parsing DAR and DALF files
To parse a DAR or DALF file from within Scala code, thecom-daml:daml-lf-archive-reader library on Maven provides a Scala package object com.digitalasset.daml.lf.archive with several decoders. Below are the common types of inputs and outputs a decoder can have, and which decoders to use depending on the input and output that is desired. For more details on inputs, outputs, and decoders, please refer to Maven to find the source code for the associated libraries.
Output types
When decoding a package, a decoder can have one of several possible outputs, depending on what is needed.-
When the full code of the package is needed, pick a decoder returning tuples
(PackageId, Package). In this case,PackageIdis a string-like type that comes fromcom.digitalasset.daml.lf.language.Refin thecom.daml:daml-lf-datalibrary on Maven.Packagerepresents the full structure of a package, and comes fromcom.digitalasset.daml.lf.language.Ast, in thecom.daml:daml-lf-languagelibrary on Maven. Because fully decoding the package takes more processing time than the next two examples, only use it when the full package code is needed. For example, thecom.digitalasset.daml.lf.typesig.reader.SignatureReaderclass from thecom-daml:daml-lf-api-type-signaturelibrary on Maven takes a(PackageId, Package)pair to produce acom.digitalasset.daml.lf.typesig.PackageSignature(also from theapi-type-signature) package, which specifies all of the templates, datatypes, and interfaces in a package. -
When only the simplest representation of the protobuf of the package is needed, pick a decoder returning a
com.digitalasset.daml.lf.ArchivePayload(from thecom-daml:daml-lf-archivelibrary on Maven). This should only be needed when working with internal protobuf representations of a package. -
When only the package’s byte representation and hash is needed, use a decoder that returns
Archive(from thecom-daml:daml-lf-archive-protolibrary on Maven). When using this, the decoder will not spend time decoding any of the package’s actual content, such as its metadata or its code.
Input types
A decoder can either accept DALF files, DAR files, or it can accept both.- If a decoder accepts DALF files, it will parse the single package in that DALF file to its output type (one of the three specified above).
- If a decoder accepts DAR files, it will parse multiple packages from a DAR file to a struct
Dar[X], which is a case class that encodes a DAR as two public fields,main: Xanddependencies: List[X]. - If a decoder accepts both, it will always produce a
Dar[X]. When given a DAR, the decoder will run as a normal DAR decoder would. When given a DALF, the decoder will decode the DALF as a single package and return aDar[X]with amainpackage and an empty list of dependencies.
Decoders
Decoders for reading DALFs are instances ofGenReader[X], which provides the method readArchiveFromFile(file: java.io.File): Either[Error, X].
-
val ArchiveReader: GenReader[ArchivePayload]RunArchiveReader.readArchiveFromFile(new java.io.File("<path-to-dalf>"))to parse out theArchivePayloadof a dalf file. -
val ArchiveDecoder: GenReader[(PackageId, Ast.Package)]RunArchiveDecoder.readArchiveFromFile(new java.io.File("<path-to-dalf>"))to parse out the(Ref.PackageId, Ast.Package)of a dalf file. -
val ArchiveParser: GenReader[DamlLf.Archive]RunArchiveParser.readArchiveFromFile(new java.io.File("<path-to-dalf>"))to parse out theDamlLf.Archiveof a dalf file.
GenDarReader, which provides the method readArchiveFromFile(file: java.io.File): Either[Error, Dar[X]].
-
val DarReader: GenDarReader[ArchivePayload]RunDarReader.readArchiveFromFile(new java.io.File("<path-to-dar>"))to parse out theDar[ArchivePayload]of a dar file. -
val DarDecoder: GenDarReader[(PackageId, Ast.Package)]RunDarDecoder.readArchiveFromFile(new java.io.File("<path-to-dar>"))to parse out theDar[(Ref.PackageId, Ast.Package)]of a dar file. -
val DarParser: GenDarReader[DamlLf.Archive]RunDarParser.readArchiveFromFile(new java.io.File("<path-to-dar>"))to parse out theDar[DamlLf.Archive]of a dar file.
GenUniversalArchiveReader, which provides the method readFile(file: java.io.File): Either[Error, Dar[X]].
-
val UniversalArchiveReader: GenUniversalArchiveReader[ArchivePayload]RunUniversalArchiveReader.readFile(new java.io.File("<path-to-dar-or-dalf>"))to parse out theDar[ArchivePayload]of a dar file. -
val UniversalArchiveDecoder: GenUniversalArchiveReader[(PackageId, Ast.Package)]RunUniversalArchiveDecoder.readFile(new java.io.File("<path-to-dar-or-dalf>"))to parse out theDar[(Ref.PackageId, Ast.Package)]of a dar file.
Example
We can load up a Scala REPL with thedaml-lf-archive-reader library to interactively parse our mypkg DAR:
.all which returns the main package and dependencies as a single list. Mapping _1 over this gets all of the package IDs in the DAR:
.metadata.name field in the Ast.Package datatype: