How do you deal with multiple DAR files with the same module/template name on a ledger?

And how can I create a clean slate on the ledger, so that I can be sure that there are no multiple DAR files with the same module name / template name?

I’m working with a DAML on Fabric ledger, restarted the Fabric instance, restarted the DAML on Fabric connector, deployed the DAR, started the JSON API, and still, when I try this command:

{
  "templateId": "Main:Record",
  "payload": {
    "documentKey": "abcd",
    "documentHash": "efgh",
    "admin": "Admin"
  }
}

I get this error message:

{
    "errors": [
        "JsonError: Cannot resolve template ID, given: TemplateId(None,Main,Record)"
    ],
    "status": 400
}

This is ok:

{
  "templateId": "395d5b4608b9cdc3aef120755ab73a523adfb7758bfe0fac441a676569e4620f:Main:Record",
  "payload": {
    "documentKey": "abcd",
    "documentHash": "efgh",
    "admin": "Admin"
  }
}

With the result:

{
    "result": {
        "agreementText": "",
        "contractId": "00daeb4ff68b04e0d1256e5097cb4f37c8621a7792227c94bd6904706dbf9bf948",
        "key": {
            "_1": "Admin",
            "_2": "abcd"
        },
        "observers": [],
        "payload": {
            "documentKey": "abcd",
            "documentHash": "efgh",
            "admin": "Admin"
        },
        "signatories": [
            "Admin"
        ],
        "templateId": "395d5b4608b9cdc3aef120755ab73a523adfb7758bfe0fac441a676569e4620f:Main:Record"
    },
    "status": 200
}
3 Likes

Is it possible that your DAR contains two modules called Main, e.g., one from a dependency?

There is no generic functionality for resetting a ledger and I’m not too familiar with DAML on Fabric. I would have expected your approach to reset everything but if it doesn’t @sormeter might be able to help you figure out how to reset it.

The other option could be that you are accessing the JSON API too quickly before it has fetched the package (I believe it defaults to fetching every 5 seconds).

3 Likes

It must have been a name clash, I had a Record template in my Main file. After having changed the template name to RecordData, I could issue the API calls with the short template id “Main:RecordData”.

Otherwise, restarting Fabric deleted all the uploaded packages. I can check this with the gRPC command

bgy@BGY ~ % grpcurl -plaintext localhost:6865 com.daml.ledger.api.v1.admin.PackageManagementService/ListKnownPackages