Published 27 June 2019

Examples: C++: Get Balance

Project:

https://github.com/CREDITSCOM/examples

Branch:

https://github.com/CREDITSCOM/examples/tree/master/API/CreditsCPlusPlusDemoCMake

 

In order to get wallet balance one needs to share wallet public key to the class Client

Client.h

void set_keys(const std::string& publicKey, const std::string& privateKey, const std::string& targetKey);

Client.cpp

void client::set_keys(const std::string& publicKey, const std::string& privateKey, const std::string& targetKey)

{

   m_keys = make_unique<keys>(publicKey.c_str(), privateKey.c_str(), targetKey.c_str());

}

and call 

Client.h

void wallet_balance_get();

Client.cpp

void client::wallet_balance_get()

{

   try

   {

      // method call result returns to this structure

      WalletBalanceGetResult bg_res;

      // second parameter shares wallet public key shared by us

      m_api->WalletBalanceGet(bg_res, m_keys->PublicKeyAddress());

      bg_res.printTo(std::cout);

   }

   catch (const std::exception&)

   {

       throw exception("wallet_balance_get: calling error");

   }

}

Call example

int main(int argc, char* argv[])

{

   auto c = make_unique<client>(“127.0.0.1”, 9090);

   c->set_keys(“ your public key ”, “”, “”);

   //the method prints wallet balance on the screen

   c->wallet_balance_get();

}

Votes 0, average rating 0

Contents