Is there any exposed API for fetching archived contracts? If not, how can I fetch archived contracts in java application?
The short answer is no, you can’t fetch an inactive (archived) contract in DAML.
There are a number of reasons for this, the most pragmatic is that it would require storing and indexing every contract ever created since genesis—and that would be prohibitive. From a theoretical perspective, this would represent reasoning from
false, which is not valid.
However these reasons only apply to DAML code, and impose no such restrictions on any applications built on top of the ledger-api. Any Java application will need to process the transaction service—even if it bootstraps from the active contract service. Generally you will extract and store some subset of the active-contract set; however, you are under no obligation to remove an entry from your application db just because it was archived.
In our DAML application, most of our ledger-api clients do in fact delete contract data once the contract is archived; however, not all of them do. Some of them (mostly reporting and diagnostic tools) mark contract data as inactive rather than deleting it, we do that precisely because we want these clients to be able to access an analyse inactive contracts.
However these reasons only apply to DAML code, and impose no such restrictions on any applications built on top of the ledger-api.
For instance if you use the
daml navigator, there is a checkbox that allows you to display archived contracts.