How to clean up Ledger

I am using DAML on Fabric and I have created some instances of the daml template on fabric ledger, Now, I wanted to know , how we can clean up the ledger. Is there some command through which all those instances would get deleted?

2 Likes

Each template implicitly has an Archive choice that you can use to archive a contract. It requires authorization from all signatories.

To call that choice you can use Daml Script’s archiveCmd, Navigator or really any other ledger client application.

1 Like

I am able to archive it using postman, but can you point me to a link if it exists, that can tell me how to archive all contracts of a particular template. There should be one command that can do this through CLI. This way I won’t need the contract Id of every contract that I want to delete. I can simply run that command and do it.

There is no single command to archive all contracts of a particular template. What you can do is to query all contracts visible to a given (set of) parties and then archive those. E.g., here’s how you can do that using Daml Script.

cids <- query @T p1 -- get all contracts of template T visible to p1
let archivableCids = filter (\(_, c) -> signatory c == [p1]) cids -- filter to contracts where p1 is the only signatory
submit p1 $ mapA archiveCmd (map fst archivableCids)  -- archive the contracts
3 Likes

I am doing this through DAML JSON APi, so wanted to know, if there is some API in DAML. That deletes all the contracts that were created in fabric ledger

1 Like

Nothing builtin there either but you can either run Daml Script over the JSON API by passing the --json-api flag or you can do it manually:

  1. First, get the list of active contracts via /v1/query.
  2. Then archive them. The easy but slow solution is to send one command to archive each contract. Alternatively, you can go via createAndExercise to archive multiple in one go. See Json api v1/create multiple records embedded in json file - #8 by cocreature for a description of that approach.
1 Like