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.

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

// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

//! cargo run --example get_balance --release
// In this example we sync the account and get the balance
// Rename `.env.example` to `.env` first

use iota_wallet::{account_manager::AccountManager, Result};

async fn main() -> Result<()> {
// Create the account manager
let manager = AccountManager::builder().finish().await?;

// Get the account we generated with `01_create_wallet`
let account = manager.get_account("Alice").await?;

// Sync and get the balance
let _account_balance = account.sync(None).await?;
// If already synced, just get the balance
let account_balance = account.balance().await?;

println!("{:?}", account_balance);


Run the Example

Run the example by running the following command:

cargo run --example get_balance --release

Expected Output

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

nfts: [

aliases: [

foundries: [

potentially_locked_outputs: {