Search code examples
blockchainnearprotocol

NEAR cli contract call works but fails when called from js sdk with same params


I have a contract running on the Near blockchain. It accepts a deposit as a payment and has the [payable] attribute on the method. Calling this contract from the Near cli with like this - near call sam2.testnet process_play_request --accountId sam2.testnet --deposit 0.005 works fine and returns hello world.

let res = await contract.process_play_request(
    {},
    undefined, // attached GAS (optional)
    nearAPI.utils.format.parseNearAmount("0.005")
);

However calling the same contract, with the same account logged in, using the above JS code throws the following error Error: {} at Object.parseRpcError Other methods on the same contract work fine it's only when i try to use the Deposit functionality that it seems to fall apart. Attaching the proper GAS amount still returns the same error.

Can anyone see what I am doing wrong with the JS code.


Solution

  • Solution

    Following on from Serhii's answer above. The actual error that was thrown was that my app didn't have permission to transfer tokens. I had to logout of my app and re-login to the sam2 account, it added full key permissions, meaning the JS posted in my question works as expected.