Runtime error creating contract on ledger API

Dear Experts,

Help! I cannot get round this runtime error trying to create a contract using the ledger API. Any thoughts on where I am going wrong?

java.lang.RuntimeException: java.util.concurrent.ExecutionException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Command interpretation error in LF-DAMLe: unknown module 86828b9843465f419db1ef8a8ee741d1eef645df02375ebf509cdc8c3ddd16cb:Trade while looking for record 86828b9843465f419db1ef8a8ee741d1eef645df02375ebf509cdc8c3ddd16cb:Trade:Trade. Details: N/A.

Looks like its missing the template or module in the request, but I am lost in where to add it.

Code:

DamlRecord recordDaml = new DamlRecord(

        new DamlRecord.Field("newBuyer", new Party("TRADER_DAML")),

        new DamlRecord.Field("newSeller", new Party("TRADER_A")),

        new DamlRecord.Field("newVolume", new Numeric(new BigDecimal(trade.getTradeVolume()))),

        new DamlRecord.Field("newPrice", new Numeric(new BigDecimal(trade.getTradePrice()))),

        new DamlRecord.Field("newTimestamp", new Timestamp(trade.timeStampInMs))

    );

            

    Identifier dalmIdentifier = new Identifier(packageId, "Trade", "Trade");

    CreateCommand createCommand = new CreateCommand(dalmIdentifier, recordDaml);



    client.getCommandClient().submitAndWait(

        String.format("Trade-%s-%d", "TRADER_DAML", numberOfLinesWritten),

        "TraderApp",

        UUID.randomUUID().toString(),

        "DAML_TRADER",

        Collections.singletonList(createCommand)

   ).blockingGet();

Template:

module Trade where

type TradeCid = ContractId Trade

template Trade

with

buyer : Party

seller : Party

volume: Decimal

price: Decimal

timestamp: Datetime

observers : [Party]

where

ensure volume > 0.0

signatory buyer

observer observers

Usually this means you need to upload your dar (the compiled output containing Trade) to the ledger. See #2, #3 in this comment for the two main ways to do this, one of which should be the most convenient for you.

If you have uploaded the dar, this error means your package ID doesn’t match what was uploaded. The best way to avoid this (as well as to make your payloads more pleasant) is to use the Java codegen as part of your build process, so that changes to your Daml always yield a Java codegen rerun and a dar upload to dev server, in lockstep.

1 Like