Accessing Command and Workflow Ids inside Daml code


I’m working on a logging solution. What I need to do is when someone exercises a choice on a contract, and some condition is true, I need to create a log contract with the command and workflow ids of the initiating command in it. Can I access the command and workflow ids inside Daml code?

Thank you!

1 Like

The command and workflow identifiers don’t exist in Daml, they are products of the Ledger API.

What you can do is listen on the Ledger API for the choices you want to log and create a contract at that point, issuing a new command.

Hopefully log contracts don’t need logging, otherwise you’ll see a lot of activity on the ledger. :wink:

I’m not sure about your requirements, but in general this looks like a fact that you can always† derive from what’s stored on the ledger through the Ledger API, so you may want to consider using an off-ledger solution for this.

† modulo pruning


Given that the command id is passed in from the client, you could perhaps also pass it in as a choice argument in addition to the commadn id field and get access to it in Daml that way. Of course you are relying on the client app to keep the two in sync but I think in a lot of cases this could be a reasonable assumption.