To show what a user currently has in their account, applications must be able to fetch the account's
Balance
s. A user's account will have a Balance
for every token/asset which the account has
received. Balance
s for various tokens can be fetched individually or all at once.
The code provided below can be used to fetch the MobileCoin balance of a user's account:
MobileCoinClient mobileCoinClient = new MobileCoinClient(
accountKey,
FOG_URI,
CONSENSUS_URI,
TransportProtocol.forGRPC()
);
Balance balance = mobileCoinClient.getBalance(TokenId.MOB);
The balance of any arbitrary token ID can retrieved using:
mobileCoinClient.getBalance(TokenId.from(myTokenId));
Balances of all tokens on the account can be fetched all at once using:
Map<TokenId, Balance> balances = mobileCoinClient.getBalances();