Published 4 July 2019

Examples: JS: Get Balance




In this example all interactions with Credits API will be implemented in the class CreditsUtils

The example describes how to get balance of a wallet using the Credits API 

Connection parameters, wallet keys and destination address are shared in the constructor

class CreditsUtils {

   constructor(publicKey, privateKey, targetKey, url) {

       this.publicKey = publicKey;

       this.privateKey = privateKey;

       this.targetKey = targetKey;

       this.url = url;

       this.publicKeyByte = from_b58(this.publicKey);

       this.privateKeyByte = from_b58(this.privateKey);

       this.targetKeyByte = from_b58(this.targetKey);


   walletGetBalance() {

       var balance = this.client().WalletBalanceGet(this.publicKeyByte).balance;

       return balance;


   client() {

       var transport = new Thrift.Transport(this.url);

       var protocol = new Thrift.Protocol(transport);

       return new APIClient(protocol);





       function run()


           var pubkey = "your public key";

           var prvkey = "your private key";

           var trgKey = "your target key";

           var url = "";

           var client = new CreditsUtils(pubkey, prvkey, trgKey, url);




Votes 0, average rating 0