Eos: how can i get account balance info when developing smart contract

Created on 27 Jun 2018  ยท  6Comments  ยท  Source: EOSIO/eos

hi , how can i get account balance info when developing smart contract. I can't find any account api in EOSIOLIB

Support

Most helpful comment

Nope, you don't need to send an action to eosio.token. The data is stored in the table of eosio.tokens, so you can just query it using multi index table.
Example:

#include "fill_the_path_to_eosio.token.hpp_here"
...
        eosio::token t(N(eosio.token));
        const auto sym_name = eosio::symbol_type(S(4,SYS)).name();
        const auto my_balance = t.get_balance(N(myaccount), sym_name );
        eosio::print("My balance is ", my_balance);
...

All 6 comments

It's inside eosio.token accounts table

@andriantolie thanks, so i should send an action to eosio.token contract in order to get the balance? How can i get the return value after sended an action?

Nope, you don't need to send an action to eosio.token. The data is stored in the table of eosio.tokens, so you can just query it using multi index table.
Example:

#include "fill_the_path_to_eosio.token.hpp_here"
...
        eosio::token t(N(eosio.token));
        const auto sym_name = eosio::symbol_type(S(4,SYS)).name();
        const auto my_balance = t.get_balance(N(myaccount), sym_name );
        eosio::print("My balance is ", my_balance);
...

@andriantolie thanks. : )

How can we do it using the new CDT compiler?

I found this to be helpful
https://github.com/EOSIO/eos/issues/3954#issuecomment-573394063

Was this page helpful?
0 / 5 - 0 ratings