Here we can see how to check the balance of all of the accounts or only of a single account of your wallet. Even though the function getBalanceFromAccount does not need a synchronization the function getBalance does.
import { ConnectionService, Environments, WalletService, Logger, AddressType } from"../src";constckbUrl="http://localhost:8117/rpc";constindexerUrl="http://localhost:8117/indexer";constmnemonic="private pond zero popular fashion omit february obscure pattern city camp pistol";constmain=async () => {try {constconnectionService=newConnectionService(ckbUrl, indexerUrl,Environments.Testnet);constwallet=newWalletService(connectionService, mnemonic);awaitwallet.synchronize();constbalanceAcc0Rec=awaitwallet.getBalanceFromAccount(0,AddressType.Receiving);Logger.info(balanceAcc0Rec);constbalanceAcc0Chg=awaitwallet.getBalanceFromAccount(0,AddressType.Change);Logger.info(balanceAcc0Chg);constbalanceAcc1=awaitwallet.getBalanceFromAccount(1,AddressType.Receiving);Logger.info(balanceAcc1);consttotalBalance=awaitwallet.getBalance();Logger.info(totalBalance); } catch (error) {Logger.error(`${error.name}: ${error.message}`); }};main();
If you want the balance of for example only ckb or only tokens or only nfts, we have dedicated functions as you can see in our documentation.