Display contractid in DAML script

Anyone know how to display contractId in DAML Script?

I tried debug (show cid) but in the Trace section, I only get "<contract-id>" instead of the real contract id string.

The behaviour you are observing stems from DAMLs core use as a smart contract language. When DAML transactions are processed, some magic happens to contract ids. At the time of interpretation on the participant node, the transaction ID isn’t known yet, so the final contract ids are also not known. Thus it’s not possible to give access to contract ids inside DAML contracts. But since all contracts should be serializable to Text and contract ids can be stored on contracts, the placeholder "<contract-id>" was put in place.

When DAML Script was developed, it inherited this placeholder from the contracts side, even thought the underlying reason doesn’t apply. Changing the behaviour requires a change in our intermediary language DAML-LF and we haven’t released a new version of that since March. Because of that, you can’t currently get your hands on the contract id in Scripts with a stable version of DAML-LF.

The feature is ready in our staging DAML-LF version 1.dev, though. If you add the option

build-options:
- --target=1.dev

to your daml.yaml, you should get the actual contract ids in DAML Script. The current plan is to release the next version of DAML-LF in early 2021 and at that point this feature will become the norm.

1 Like

Obligatory mention that using --target=1.dev is not supported under any circumstances and that storing data on a persistent ledger using 1.dev will lead to data corruption.

1 Like

@bernhard thanks for your answer and looking forward to the new feature.
@Gary_Verhaegen I will keep that in mind and currently I only use that for testing inside DAML script.
Probably it is an opportunity to ask another question which is: Should I store contract Ids on other contracts?

[Edited by @bernhard to split out the new question]