TypeError: choice.argumentEncode is not a function

Hi

We recently came across a strange bug in our react.js software that caused all of our ledger.create and ledger.exercise api calls to fail. (We are on DAML SDK 1.7)

The error we are receiving is listed below

TypeError: choice.argumentEncode is not a function
    at Ledger.<anonymous> (index.js:419)
    at step (index.js:44)
    at Object.next (index.js:25)
    at index.js:19
    at new Promise (<anonymous>)
    at push.../../../../Documents/Github/Loci/ui-js/node_modules/@daml/ledger/index.js.__awaiter (index.js:15)
    at Ledger.exercise (index.js:410)
    at VendorInvite.js:101
    at VendorInvite.js:140
    at commitHookEffectListMount (react-dom.development.js:19731)
    at commitPassiveHookEffects (react-dom.development.js:19769)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)

And is triggered in the the following code of /nodes_modules/@daml/ledger/index,js

  Ledger.prototype.exercise = function (choice, contractId, argument) {
        return __awaiter(this, void 0, void 0, function () {
            var payload, json, responseDecoder, _a, exerciseResult, events;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        payload = {
                            templateId: choice.template().templateId,
                            contractId: types_1.ContractId(choice.template()).encode(contractId),
                            choice: choice.choiceName,
  --> This Line    argument: choice.argumentEncode(argument),
                        };
                        return [4 /*yield*/, this.submit('v1/exercise', payload)];
                    case 1:
                        json = _b.sent();
                        responseDecoder = jtv.object({
                            exerciseResult: choice.resultDecoder,
                            events: jtv.array(decodeEventUnknown),
                        });
                        _a = jtv.Result.withException(responseDecoder.run(json)), exerciseResult = _a.exerciseResult, events = _a.events;
                        return [2 /*return*/, [exerciseResult, events]];
                }

Also, the ledger create and exercise API calls in Postman are working

Any suggestions on where we should look to solve this problem ?

1 Like

Can you share the callsite of exercise? My suspicion is that either you are not passing the choice argument generated by the codegen or you generated code for a different SDK version than you have specified in your package.json.

1 Like

This is just one of the ledger,exercise that is failing

ledger.exercise(Roles.PartyInvitation.AcceptVendorInvitation, curContractId, { operator, vendor: roleone, vendordetails: onedetailParams })

I checked package.json and

have the following entries as dependencies

    "@daml/ledger": "^1.1.1",
    "@daml/react": "^1.1.1",
    "@daml/types": "^1.1.1",
    "@daml2js/DAMLLoci-0.0.1": "file:../daml2js/DAMLLoci-0.0.1",  -> this is the Dar location

daml.yaml shows

sdk-version: 1.7.0

however in nodes_modules@daml\ledger\package.json I found the following reference to version 1.8.0

{
  "private": false,
  "name": "@daml/ledger",
  "version": "1.8.0",
  "description": "Client side API implementation for a DAML based ledger. This library implements the JSON based API for a DAML ledger documented in https://docs.daml.com/json-api/index.html.",

  "keywords": [
    "daml",
    "API",
    "client"
  ],
  "homepage": "https://daml.com",
  "repository": {
    "type": "git",
    "url": "https://github.com/digital-asset/daml.git",
    "directory": "language-support/ts/daml-ledger"
  },
  "main": "index.js",
  "types": "index.d.ts",
  "license": "Apache-2.0",
  "dependencies": {
    "@daml/types": "1.8.0",
    "@mojotech/json-type-validation": "^3.1.0",
    "cross-fetch": "^3.0.4",
    "events": "^3.1.0",
    "isomorphic-ws": "^4.0.1",
    "ws": "^7.2.1"
  },
  "scripts": {
    "build": "tsc --build",
    "build:watch": "tsc --build --watch",
    "test": "jest",
    "lint": "eslint --ext .ts --ignore-pattern lib/ --max-warnings 0 ./"
  },

  "devDependencies": {
    "@types/jest": "^24.0.23",
    "@types/lodash": "4.14.161",
    "@types/ws": "^7.2.1",
    "@typescript-eslint/eslint-plugin": "^2.16.0",
    "@typescript-eslint/parser": "^2.16.0",
    "eslint": "^6.8.0",
    "jest": "^24.9.0",
    "jest-mock-console": "^1.0.0",
    "ts-jest": "^24.2.0",
    "typescript": "~3.8.3"
  }
}
1 Like

The version of the @daml/* libraries must match the version of daml codegen js exactly. So assuming you want to stick to SDK 1.7.0, change the package.json to:

    "@daml/ledger": "1.7.0",
    "@daml/react": "1.7.0",
    "@daml/types": "1.7.0",
    "@daml2js/DAMLLoci-0.0.1": "file:../daml2js/DAMLLoci-0.0.1",  -> this is the Dar location

and run at least npm install and if that doesn’t help maybe try deleting node_modules and your lock file.

1 Like

Ok. Thanks. We will give it a try

we will upgrade ui-js/package.json from

@daml/ledger”: “^1.1.1”,
@daml/react”: “^1.1.1”,
@daml/types”: “^1.1.1”,

to
@daml/ledger”: “^1.7.0”,
@daml/react”: “^1.7.0”,
@daml/types”: “^1.7.0”,

Question is how did the 1.8.0 version slip in nodes_module? We did not upgrade to 1.8.0
Also why previously when we upgraded from 1.6 to 1.7 did the ui-js/package,json not upgrade with the new version ?

1 Like

sorry just realized I made a mistake above, the ^ at the beginning was wrong, you want exactly those versoins. I’ve updated my post. ^ takes any version that is semver compatible so 1.1.0 will also allow for 1.8.0.

1 Like

Ok. Thanks . Updating to

@daml/ledger”: “1.7.0”,
@daml/react”: “1.7.0”,
@daml/types”: “1.7.0”,

1 Like

This solved the problem ! Thanks @cocreature