Reading Balances

In this step, the SDK translates a single call into the process of querying a resource and reading a field from that resource.


const aliceBalance = await balance("Alice", alice.accountAddress);
const bobBalance = await balance("Bob", bob.accountAddress);

Behind the scenes, the balance function uses the SDK getAccountAPTAmount function that queries the Indexer service and reads the current stored value:


const balance = async (
name: string,
accountAddress: AccountAddress,
): Promise<number> => {
const amount = await aptos.getAccountAPTAmount({
accountAddress,
});
console.log(`${name}'s balance is: ${amount}`);
return amount;
};