Choice : Archive current contract

Hi Everyone,

I have been trying to create a choice where “signatory” party/s can exercise a choice on a specific contract to archive it.

choice Archive_Contract : ()
      controller signatory
      do
        exercise [...] Archive

I guess, I have to pass the current contractId instead of […]. Not sure if this is the right approach but I tried passing it as “this.ContractId” , but seems like its giving me a error.

Can anyone help me with the correct syntax.

Thank you!

A contract is archived by default once a choice is exercised. Assuming you don’t have the nonconsuming keyword in front of the choice, you don’t need to perform anything. You can just return (),

more about nonconsuming here
https://docs.daml.com/daml/reference/choices.html#non-consuming-choices

2 Likes

Thank you @rikotacards

1 Like

Once you’ve changed it to a non-consuming choice, you can use self to get access to the contract id of the current contract.

2 Likes

Thank you @cocreature

I do have one more question though…

As per the DAML documentation Archive choice is implicitly added to every template.

Currently I have a Java GRPC method to invoke other choices defined in the template using the “CommandServiceGrpc” stub, so wanted to know if we can invoke this Archive choice from the same as well.

Ref:
https://docs.daml.com/daml/intro/4_Transformations.html#the-archive-choice

Thank you!!

The choice is implicitly added by the compiler. So in Daml-LF it always exists and it’s available over the ledger API. The Java codegen should generate it for you like any other choice. If you don’t use the codegen, just call the choice called Archive.

2 Likes