How to get the name of a template or data type
- cohen.avrahamOP
Hello,
Let’s say that I have the following template:template Hello with owner: Party where signatory ownerHow can I print only the template name once I create it in a script? Is there something similar like the Haskell’s
typeOffunction? - bernhard 3
There is in the form of
TypeRep, but the function to print those type representations is a dev-only feature, meaning it’s only available in Daml-LF1.dev. Might be of use in a test script, but cannot be used in a package that you deploy to the ledger:module Main where import Daml.Script template Hello with owner: Party where signatory owner ttrFromCid : forall t . (Template t) => ContractId t -> TemplateTypeRep ttrFromCid x = templateTypeRep @t setup : Script () setup = script do owner <- allocatePartyWithHint "owner" (PartyIdHint "owner") helloCid <- submit owner do createCmd Hello with .. Some hello <- queryContractId owner helloCid let tr = ttrFromCid helloCid debug (templateTypeRepToText tr)Requires in
daml.yaml:build-options: - --target=1.devYou’ll get output (in the IDE):
Trace: "-homePackageId-:Main:Hello" - cohen.avraham
Thanks @bernhard,
Why is this limited to dev only? I would like to have this not only in dev environment. - bernhard 1
Adding stable features has ongoing cost as Daml has strong backwards compatibility guarantees. Whether this particular feature has enough value is not clear. We have opened a ticket here for discussion: Investigate impact/need of providing template names in Daml Script · Issue #19604 · digital-asset/daml · GitHub