Skip to main content

Get Coin Balance

Alpha Software

The IOTA SDK is currently in alpha. APIs, interfaces, and behavior may change without notice between releases. It is not yet recommended for production use.

This guide shows you how to retrieve the coin balance for an IOTA address using the IOTA SDK's GraphQL client.

Prerequisites

  • The IOTA SDK installed for your target language
  • A valid IOTA address on the testnet

Steps

1. Initialize the GraphQL Client

Create a client connected to the IOTA Testnet.

crates/iota-sdk/examples/coin_balances.rs
loading...

2. Parse the Address

Parse the target IOTA address from a hex string.

crates/iota-sdk/examples/coin_balances.rs
loading...

3. List All Coins

Query all individual coin objects owned by the address.

crates/iota-sdk/examples/coin_balances.rs
loading...

4. Get the Total Balance

Query the total aggregated balance across all coins for the address.

crates/iota-sdk/examples/coin_balances.rs
loading...

Expected Output

Coin = 0x<object-id>, Coin Type = 0x2::iota::IOTA, Balance = <amount-in-nanos>
Coin = 0x<object-id>, Coin Type = 0x2::iota::IOTA, Balance = <amount-in-nanos>
...
Total Balance = <total-amount-in-nanos>
tip

Balances are denominated in nanos (the smallest IOTA unit). To convert to IOTA, divide by 1_000_000_000.

Full Example

crates/iota-sdk/examples/coin_balances.rs
loading...