2

How can I get the contract id when exercising a choice since this refers to the current contract but not the contract id?

I can not find it through DAML SDK.

AS Mackay
  • 2,831
  • 9
  • 19
  • 25

2 Answers2

1

In a non-consuming choice there is an implicit variable self that provides the contract-id of the current contract. This is similar to the implicit variable this that provides the contract contents within a choice.

The current DAML semantics specify that a contract is archived at the beginning of a consuming choice, so even if you had access to self in a consuming choice, there is nothing you could do with it.

Recurse
  • 3,557
  • 1
  • 23
  • 36
1

The implicit self variable is actually visible within all choices, non-consuming or otherwise. As pointed out though, currently it's of no value in a consuming choice because the behavior of a consuming choice is that the contract instance on which the choice is exercised is archived before execution of the choice body (that is, the semantics are "pre-consuming"). In a future release the set of choice annotations will expand to include preconsuming and postconsuming. In a post-consuming choice, the contract referred to by self will remain active throughout the choice body and be archived at the end. A choice not annotated with preconsuming, noconsuming or postconsuming will default to the pre-consuming semantics (just as it is today).