Querying Specific Tokens: A Comprehensive Guide to Wallet Asset Management

ยท

This guide explains how to query balances of specific tokens within a wallet account using Web3 API functionality.

Understanding Token Balance Queries

The token balance query feature allows users to retrieve balance information for designated tokens associated with their wallet. This functionality is essential for:

๐Ÿ‘‰ Explore advanced wallet management tools for comprehensive asset oversight.

API Request Structure

Endpoint

POST `https://web3.okx.com/api/v5/wallet/asset/token-balances`

Required Parameters

ParameterTypeRequiredDescription
accountIdStringYesUnique account identifier
tokenAddressesArrayYesList of tokens (maximum 20)
chainIndexStringYesBlockchain network identifier
tokenAddressStringYesToken contract address ("" for native currency)

Token Address Specifications

  1. Native Currency: Use empty string "" to query the chain's base currency
  2. Standard Tokens: Provide the contract address
  3. Inscription Tokens:

    • FBRC-20: Format as fbtc_fbrc20_name
    • BRC-20: Format as btc-brc20-tick(name)
    • Runes: Format as btc-runesMain-tickId
    • SRC-20: Format as btc-src20-name

Response Structure

ParameterTypeDescription
tokenAssetsArrayList of token balances
chainIndexStringBlockchain identifier
tokenAddressStringToken contract address
symbolStringToken ticker symbol
balanceStringFormatted token amount
rawBalanceStringRaw token amount (when available)
tokenPriceStringUSD valuation
tokenTypeString1 for token, 2 for inscription
isRiskTokenBooleanRisk token indicator

๐Ÿ‘‰ Learn about token security best practices to protect your assets.

Implementation Examples

Sample Request

{
  "accountId": "wallet_12345",
  "tokenAddresses": [
    {
      "chainIndex": "1",
      "tokenAddress": "0x123...abc"
    },
    {
      "chainIndex": "2",
      "tokenAddress": ""
    }
  ]
}

Sample Response

{
  "tokenAssets": [
    {
      "chainIndex": "1",
      "tokenAddress": "0x123...abc",
      "symbol": "TOK",
      "balance": "100.50",
      "rawBalance": "100500000000000000000",
      "tokenPrice": "1.25",
      "tokenType": "1",
      "isRiskToken": false
    }
  ]
}

FAQ Section

Q: What's the maximum number of tokens I can query at once?

A: The API supports querying up to 20 tokens in a single request.

Q: How do I query native currency balances?

A: For native currency (like ETH on Ethereum), use an empty string "" as the tokenAddress parameter.

Q: What does isRiskToken indicate?

A: This flag identifies potentially risky airdropped tokens that may have security or regulatory concerns.

Q: Why might rawBalance be empty?

A: Raw balance isn't available for all blockchain networks. The field will be empty for unsupported chains.

Q: How frequently should I check token balances?

A: For active traders, we recommend checking balances at least daily. Casual users might check weekly.

Q: Can I query historical balance information?

A: This particular endpoint provides current balances only. Historical data requires different API endpoints.