Icon SunFilledIcon MoonStars

Icon LinkChecking balances and coins

First, one should remember that, with UTXOs, each coin is unique. Each UTXO corresponds to a unique coin, and said coin has a corresponding amount (the same way a dollar bill has either 10$ or 5$ face value). So, when you want to query the balance for a given asset ID, you want to query the sum of the amount in each unspent coin. This querying is done very easily with a wallet:

	import { Wallet, WalletUnlocked, BigNumberish} from 'fuels';
	const balance: BigNumberish = await myWallet.getBalance(BaseAssetId);

If you want to query all the balances (i.e., get the balance for each asset ID in that wallet), you can use the getBalances method:

	import { Wallet, WalletUnlocked, CoinQuantity} from 'fuels';
	const balances: CoinQuantity[] = await myWallet.getBalances();

Was this page helpful?