1

I am trying to get user tokens with the following method:

static async getUserTokens(userAccount) {
    console.log("Get tokens for: " + userAccount);
    try {
      const rpc = new JsonRpc("http://127.0.0.1:8888", { fetch });
      const resp = await rpc.get_currency_balance({
        code: "electro.coin",
        account: "bob",
        symbol: "EL"
      });
      //console.log(resp.rows[0]);
      return resp.rows[0];
    } catch (err) {
      console.error(err);
    }
  }

and it returns:

eosjs-jsonrpc.js:99 POST http://127.0.0.1:8888/v1/chain/get_currency_balance 500 (Internal Server Error)
Error: Invalid cast from type 'object_type' to string
    at new RpcError (eosjs-rpcerror.js:23)
    at JsonRpc.eval (eosjs-jsonrpc.js:118)
    at step (eosjs-jsonrpc.js:36)
    at Object.eval [as next] (eosjs-jsonrpc.js:17)
    at fulfilled (eosjs-jsonrpc.js:8)

Any explanation what am I missing? The token contract is electro.coin, the user is bob and the symbol is EL. I hard-coded the elements for better debugging, but no luck so far...

2
  • 1
    Have you tried converting the object to a string to satisfy the error message? JSON.stringify(data) Commented Jul 26, 2019 at 1:47
  • It appears that my whole data was added to the scope field and the other fields stayed as undefined. Thank you @PhillipHamnett for the hint, now I am using: const resp = await rpc.get_currency_balance("electro.coin", userAccount, "EL"); and it works :) Commented Jul 26, 2019 at 21:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.