javascriptpact-langkadena

Kadene transfer-create call fails


I'm trying to call transfer 10 K tokens to account k:81df193e0d913bc87e127150efdaaee39584abbd2d0223ed8c9afb0b31cf9db2, with transfer-create function. However it fails and the error message is here =>

Request key: VWFFgiP3fVdMpkwh3HoRNsyJQu5r21K7BrP6IYebTrg
js/index.js:146
Transaction pending...
js/index.js:147
Transaction mined!
js/index.js:153
{
  "gas": 600,
  "result": {
    "status": "failure",
    "error": {
      "callStack": [],
      "type": "EvalError",
      "message": "",
      "info": ""
    }
  },
  "reqKey": "VWFFgiP3fVdMpkwh3HoRNsyJQu5r21K7BrP6IYebTrg",
  "logs": "QJwoDEUraWkAdNhOm6XLEl1n-VfamHTwY-I-sMfMfGQ",
  "events": [
    {
      "params": [
        "sender00",
        "k:f89ef46927f506c70b6a58fd322450a936311dc6ac91f4ec3d8ef949608dbf1f",
        0.00006
      ],
      "name": "TRANSFER",
      "module": {
        "namespace": null,
        "name": "coin"
      },
      "moduleHash": "rE7DU8jlQL9x_MPYuniZJf5ICBTAEHAIFQCB4blofP4"
    }
  ],
  "metaData": {
    "blockTime": 1670022922909513,
    "prevBlockHash": "AZ6zoGd8Bj3OhyOWtf1MpFHGUuTCF1F9bizLDe6zhnA",
    "blockHash": "mwiya3qCmq6w120nxO_IXZegM8S_FREmm54CbbJQX0k",
    "blockHeight": 2101
  },
  "continuation": null,
  "txId": null
}

Javascript function call

await transferCreateKTokenAccount(
  "ktoken", 
  "k:81df193e0d913bc87e127150efdaaee39584abbd2d0223ed8c9afb0b31cf9db2",
  10)
async function transferCreateKTokenAccount(sender, newAccount, amount) {
  const cmd = {
    networkId: NETWORK_ID,
    keyPairs: [
      Object.assign(KEY_PAIR, {
        clist: [
          Pact.lang.mkCap(
            "GAS",
            "Capability to allow buying gas",
            "coin.GAS",
            []
          ).cap,
          Pact.lang.mkCap(
            "Transfer",
            "Capability to allow coin transfer",
            "coin.TRANSFER",
            [sender, newAccount, { decimal: amount }]
          ).cap
        ]
      })
    ],
    pactCode: `(free.ktoken.transfer-create  "${sender}" "${newAccount}" (read-keyset "account-keyset") ${amount})`,
    envData: {
      "account-keyset": {
        keys: [
          // Drop the k:
          newAccount.substr(2)
        ],
        pred: "keys-all"
      }
    },
    meta: {
      creationTime: creationTime(),
      ttl: 28000,
      gasLimit: 600,
      chainId: CHAIN_ID,
      gasPrice: 0.0000001,
      // sender: sender
      sender: `sender00`
    }
  };

  const response = await Pact.fetch.send(cmd, API_HOST);
  console.log(`Request key: ${response.requestKeys[0]}`);
  console.log("Transaction pending...");

  const txResult = await Pact.fetch.listen(
    { listen: response.requestKeys[0] },
    API_HOST
  );
  console.log("Transaction mined!");
  console.log(JSON.stringify(txResult, null, 2));
}

await transferCreateKTokenAccount(
  `ktoken`, 
  `k:81df193e0d913bc87e127150efdaaee39584abbd2d0223ed8c9afb0b31cf9db2`,
  10)

transfer-create implementation in the pact contract is

  ;; ; --------------------------------------------------------------------------
  ;; ; Fungible-v2 Implementation

  (defun transfer-create:string
    ( sender:string
      receiver:string
      receiver-guard:guard
      amount:decimal )

    @doc " Transfer to an account, creating it if it does not exist. "

    @model [ (property (conserves-mass amount))
             (property (> amount 0.0))
             (property (valid-account-id sender))
             (property (valid-account-id receiver))
             (property (!= sender receiver)) ]

    (with-capability (TRANSFER sender receiver amount)
      (debit sender amount)
      (credit receiver receiver-guard amount)
    )
  )

Solution

  • This happens because a recent change in the node software. For stability the logs are no longer written on the blockchain. To obtain an error message for your transaction you should first run it using the /local preview endpoint.

    See also release notes for the node software: https://github.com/kadena-io/chainweb-node/releases/tag/2.17