5

In the new version of eosjs, the getCurrencyBalance() method is no longer supported. How can I still get the currency balance of an account using eosjs?

1
  • I think now you have to get the currency table of eosio.token as we did while we get the account balance inside contract. Now you have to call the table action using eosjs. Oct 17, 2018 at 5:22

1 Answer 1

4

In eosjs v20.x, getCurrencyBalance has been renamed to get_currency_balance, and moved within the Rpc object.

You can use it like this...

const fetch = require('node-fetch');
const { JsonRpc } = require('eosjs');

// Instantiate a new JsonRpc object, with the Network Api Uri, and a request object
const rpc = new JsonRpc('https://api.kylin.alohaeos.com', { fetch });
// Request the balance, passing in the token contract, the account name, and the token symbol
rpc.get_currency_balance('eosio.token', 'eospaceioeos', 'EOS').then((balance) => console.log(balance));
3
  • it would be great to see an updated version of this answer
    – botbot
    Mar 20, 2019 at 10:51
  • error jsonrpc not a constructor
    – botbot
    Mar 22, 2019 at 2:25
  • This answer works, thanks a lot! Nov 5, 2019 at 4:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.