Skip to main content

Check Balance

You can retrieve the balance for any account you created by calling the Account.balance() function. Bear in mind that you should always sync the account with the node to get the latest transactions.

Online Faucet

You can request test funds from the Shimmer Testnet Faucet.

Code Example

The following example will:

  1. Create an account manager.
  2. Get Alice's account which was created in the first guide.
  3. Sync the account with the node to get the latest transactions.
  4. Request the account's balance.
Unlock Conditions

Outputs may have multiple UnlockConditions, which may require returning some or all of the transferred amount. The outputs could also expire if not claimed in time, or may not be unlockable for a predefined period.

To get outputs with only the AddressUnlockCondition, you should synchronize with the option syncOnlyMostBasicOutputs: true.

If you are synchronizing outputs with other unlock conditions, you should check the unlock conditions carefully before crediting users any balance.

You can find an example illustrating how to check whether an output has only the address unlock condition and whether this address belongs to the account in the Check Unlock Conditions how-to guide.

Dotenv

This example uses dotenv, which is not safe for use in production environments.

wallet/examples/04_get_balance.rs
loading...

Run the example by running the following command:

cargo run --example get_balance --release

Expected Output

AccountBalance{
base_coin: BaseCoinBalance{
total: 100000000000,
available: 100000000000
},
required_storage_deposit: 213000,
native_tokens: [

],
nfts: [

],
aliases: [

],
foundries: [

],
potentially_locked_outputs: {

}
}