Archived a Contract

How i can Archived a contract from canton using contractId. can you please send the command for that

Hi @Joy_K,

Using which interface are you looking to do that? Are you looking for a Ledger API submission example or are you trying to achieve it using the canton console?

Kind Regard,
Mate

Anything that will work on canton console. I need that

Hi Joy_K,

The simplest way that I could find to do this from the console is as follows, assuming you have pkgId, moduleName, templateName, contractId and party defined:

val archiveCommand = ledger_api_utils.exercise(pkgId,moduleName,templateName,"Archive",Map(),contractId)
<your-participant-reference>.ledger_api.commands.submit(Seq(party),Seq(archiveCommand)) 

As an example:

/* Define the contractId for the contract you wish to Archive. */
val contractId = "004216a9008192e29ff19fbafe0e4db4c6375c01e5899b5fe19537286d9da2ded6ca01122070c134ec213147751e47b363e8c23e0dd22e43ca01ffa6de2148d3e23ce6b3be" 
/* Validate that your ACS has a contract with that ID */
participant1.ledger_api.acs.of_all().filter(_.event.contractId==contractId).size
/* Extract the template Id from the event for your contract */
val tid = participant1.ledger_api.acs.of_all().filter(_.event.contractId==contractId).head.event.templateId.get
/* Build the exercise command containing the proper payload */
val archiveCommand = ledger_api_utils.exercise(tid.packageId,tid.moduleName,tid.entityName,"Archive",Map(),contractId) 
/* Get the PartyId for the party you want to submit the command as */ 
val party = participant1.parties.list().filter(_.party.toProtoPrimitive.startsWith("participant1")).head.party
/* Submit the command */
participant1.ledger_api.commands.submit(Seq(party),Seq(archiveCommand)) 
/* Verify that your contract got archived. */
participant1.ledger_api.acs.of_all().filter(_.event.contractId==contractId).size 

Please note that the recommended way for clients to interact with the Ledger API is trough gRPC calls. For a simple client you can utilize grpcurl, but building the payloads for it in JSON can be a bit complicated.

Please also note that the ledger_api commands are in the testing set of command and not supported for production use.

Kind Regards,
Mate