suix_getBalance{deprecated} - Sui

This method retrieves an account's total coin balance for a specified coin type on the SUI network, returning the aggregated balance across all coin objects owned by the address.

This method is deprecated

Parameters

ParameterTypeRequiredDescriptionDefault/Supported Values
ownerstringYesThe owner's SUI address whose balance is being queriedMust be a valid SUI address starting with "0x"
coin_typestringNoType name for the coin to queryDefaults to "0x2::sui::SUI"

Request Example

bashcurl --location --request POST https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/ \
--header 'Content-Type: application/json' \
--data-raw '{
  "jsonrpc": "2.0",
  "method": "suix_getBalance",
  "params": [
    "0x94f1a597b4e8f709a396f7f6b1482bdcd65a673d111e49286c527fab7c2d0961"
  ],
  "id": "getblock.io"
}'
pythonimport requests
import json

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
headers = {"Content-Type": "application/json"}

payload = {
    "jsonrpc": "2.0",
    "method": "suix_getBalance",
    "params": [
        "0x94f1a597b4e8f709a396f7f6b1482bdcd65a673d111e49286c527fab7c2d0961"
    ],
    "id": "getblock.io"
}

response = requests.post(url, headers=headers, data=json.dumps(payload))

if response.status_code == 200:
    print("Result:", response.json().get("result"))
else:
    print("Error:", response.status_code, response.text)
javascriptconst axios = require('axios');

const url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/";
const payload = {
  jsonrpc: "2.0",
  method: "suix_getBalance",
  params: [
    "0x94f1a597b4e8f709a396f7f6b1482bdcd65a673d111e49286c527fab7c2d0961"
  ],
  id: "getblock.io"
};

axios.post(url, payload, {
  headers: { "Content-Type": "application/json" }
})
.then(response => {
  console.log("Result:", response.data.result);
})
.catch(error => {
  console.error("Error:", error.response?.status, error.response?.data);
});
rustuse reqwest::Client;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    
    let payload = json!({
        "jsonrpc": "2.0",
        "id": "getblock.io",
        "method": "suix_getBalance",
        "params": [
            "0x94f1a597b4e8f709a396f7f6b1482bdcd65a673d111e49286c527fab7c2d0961"
        ]
    });

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&payload)
        .send()
        .await?;

    println!("Response: {:?}", response.text().await?);
    Ok(())
}

Response

json{
  "jsonrpc": "2.0",
  "id": "getblock.io",
  "result": {
    "coinType": "0x2::sui::SUI",
    "coinObjectCount": 15,
    "totalBalance": "3000000000",
    "lockedBalance": {}
  }
}

Response Parameters

ParameterTypeDescription
jsonrpcstringThe JSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultobjectThe balance information object
result.coinTypestringThe fully qualified coin type identifier
result.coinObjectCountintegerNumber of coin objects of this type owned
result.totalBalancestringTotal balance in MIST (1 SUI = 10^9 MIST)
result.lockedBalanceobjectMap of locked balance amounts by lock identifier

Use Cases

  1. Wallet Balance Display

    The primary use case for suix_getBalance is displaying the current balance of a SUI address in wallet applications. By calling this method, a wallet app can fetch the latest aggregated balance and display it in the user interface, allowing users to track their holdings in real-time.

  2. Transaction Validation

    Before initiating a transaction, developers can use suix_getBalance to ensure that a SUI address has sufficient funds to cover the transaction amount and associated gas fees. This pre-check helps prevent failed transactions due to insufficient balance.

  3. Gas Availability Check

    Applications can verify that an account has enough SUI for gas payments before constructing complex Programmable Transaction Blocks, improving user experience by failing fast when funds are insufficient.

Error handling

ErrorDescriptionSolution
Invalid Address FormatThe SUI address is not properly formattedEnsure the address is a valid 66-character hexadecimal string starting with '0x'
Invalid Coin TypeThe specified coin type does not exist or is malformedVerify the coin type follows the format "package::module::type"
Network ErrorConnection issues with the RPC endpointCheck network connectivity and endpoint availability
Rate LimitingToo many requests to the RPC endpointImplement request throttling or use dedicated node service

SDK Integration

typescriptimport { SuiClient } from '@mysten/sui/client';

const client = new SuiClient({ url: 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' });

const balance = await client.getBalance({
  owner: '0x94f1a597b4e8f709a396f7f6b1482bdcd65a673d111e49286c527fab7c2d0961',
});

console.log(balance);
rustuse sui_sdk::SuiClientBuilder;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    let sui = SuiClientBuilder::default()
        .build("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .await?;
    
    let address = "0x94f1a597b4e8f709a396f7f6b1482bdcd65a673d111e49286c527fab7c2d0961".parse()?;
    let balance = sui.coin_read_api().get_balance(address, None).await?;
    
    println!("{:?}", balance);
    Ok(())
}