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.
- Rust
- Go
- Python
- Kotlin
- Swift
crates/iota-sdk/examples/coin_balances.rs
loading...
bindings/go/examples/coin_balances/main.go
loading...
bindings/python/examples/coin_balances.py
loading...
bindings/kotlin/examples/CoinBalances.kt
loading...
bindings/swift/examples/coin_balances.swift
loading...
2. Parse the Address
Parse the target IOTA address from a hex string.
- Rust
- Go
- Python
- Kotlin
- Swift
crates/iota-sdk/examples/coin_balances.rs
loading...
bindings/go/examples/coin_balances/main.go
loading...
bindings/python/examples/coin_balances.py
loading...
bindings/kotlin/examples/CoinBalances.kt
loading...
bindings/swift/examples/coin_balances.swift
loading...
3. List All Coins
Query all individual coin objects owned by the address.
- Rust
- Go
- Python
- Kotlin
- Swift
crates/iota-sdk/examples/coin_balances.rs
loading...
bindings/go/examples/coin_balances/main.go
loading...
bindings/python/examples/coin_balances.py
loading...
bindings/kotlin/examples/CoinBalances.kt
loading...
bindings/swift/examples/coin_balances.swift
loading...
4. Get the Total Balance
Query the total aggregated balance across all coins for the address.
- Rust
- Go
- Python
- Kotlin
- Swift
crates/iota-sdk/examples/coin_balances.rs
loading...
bindings/go/examples/coin_balances/main.go
loading...
bindings/python/examples/coin_balances.py
loading...
bindings/kotlin/examples/CoinBalances.kt
loading...
bindings/swift/examples/coin_balances.swift
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
- Rust
- Go
- Python
- Kotlin
- Swift
crates/iota-sdk/examples/coin_balances.rs
loading...
bindings/go/examples/coin_balances/main.go
loading...
bindings/python/examples/coin_balances.py
loading...
bindings/kotlin/examples/CoinBalances.kt
loading...
bindings/swift/examples/coin_balances.swift
loading...