getAccountBalance

Cosmos RPC

Overview

The getAccountBalance endpoint in the Cosmos Rosetta API allows fetching the balance for a specified account identifier at a given block. This endpoint returns the balance only for the requested account and block, without aggregating sub-account balances unless explicitly requested.

Parameters

NameTypeRequiredDescription
networkIdentifierobjectYesIdentifies the Cosmos blockchain and network details.
blockchainstring (from networkIdentifier)YesThe blockchain identifier, typically "Cosmos".
networkstring (from networkIdentifier)YesThe network name on which the transaction is taking place.
subNetworkIdentifierobject (from networkIdentifier)NoOptional sub-network identifier object.
networkstring (from subNetworkIdentifier)YesThe name of the sub-network within Cosmos.
metadataobject (from subNetworkIdentifier)NoMetadata associated with the sub-network.
accountIdentifierobjectYesContains information about the account.
addressstring (from accountIdentifier)YesThe account address associated with the operation.
sub_accountobject (from accountIdentifier)NoOptional sub-account information.
metadataobject (from accountIdentifier)NoOptional metadata for the account, including public keys if relevant.
addressstring (from sub_account)YesThe sub-account address.
metadataobject (from sub_account)NoMetadata for the sub-account.
blockIdentifierobjectNoInformation about the specific block.
indexnumber (from blockIdentifier)NoThe index of the block (Type: number, Format: int64).
hashstring (from blockIdentifier)NoThe hash of the block.
currencyobjectYesSpecifies the currency details.
symbolstring (from currency)YesThe symbol or code of the currency.
decimalsnumber (from currency)YesThe number of decimal places for the currency.
metadataobject (from currency)NoAdditional information related to the currency, such as the contract address.

Returns

FieldTypeDescription
blockIdentifierobjectThe block at which the balance was fetched.
balancesarrayA list of balances found at the specified block.

Example Result

{
  "blockIdentifier": {
    "index": 1000000,
    "hash": "C2F9D..."
  },
  "balances": [
    {
      "value": "100000000",
      "currency": {
        "symbol": "ATOM",
        "decimals": 6
      }
    }
  ]
}

Request Example

curl --location 'https://api.tatum.io/v3/blockchain/node/cosmos-mainnet/account/balance' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
    "networkIdentifier": {
        "blockchain": "cosmos",
        "network": "cosmos-mainnet"
    },
    "accountIdentifier": {
      "address": "{{address}}",
    }
}'
// Import required libraries and modules from Tatum SDK
import { TatumSDK, Cosmos, Network } from "@tatumio/tatum";

// Initialize the Tatum SDK for Cosmos
const cosmos = await TatumSDK.init<Cosmos>({
  network: Network.COSMOS_MAINNET,
});

// Define the input parameters with only required fields
const params = {
  networkIdentifier: {
    blockchain: "COSMOS",
    network: "COSMOS_MAINNET",
  },
  accountIdentifier: {
    address: "{{address}}",
  },
};

// Fetch the account balance
const accountBalance = await tatum.rpc.getAccountBalance(params);

// Log the account balance
console.log("Account Balance:", accountBalance);

// Always destroy the Tatum SDK instance when done to stop any background processes
await tatum.destroy();