Skip to Content
TokengetTokenBalanceBySymbol

getTokenBalanceBySymbol

This function fetches SPL token balance by token symbol and network.

Usage

page.tsx
import { useConnection } from "@solana/wallet-adapter-react"; import { getTokenBalanceBySymbol } from "@okito/sdk"; const {connection} = useConnection(); const target = "WALLET_ADDRESS"; // The account for which balance is requested const tokenSymbol = "USDC"; // Token symbol (e.g., "USDC", "USDT") const network = "mainnet-beta"; // Network type const tokenBalance = await getTokenBalanceBySymbol(connection, target, tokenSymbol, network)

Capabilities

  • Symbol-to-mint resolution for common tokens
  • Same balance shape as getTokenBalanceByMint
  • Network-aware lookups (mainnet-beta, devnet)

Props

NameTypeDefault
connection
Connection
The Solana `Connection` object.
-
target
PublicKey | string
The wallet address for which the token balance is being retrieved.
-
tokenSymbol
string
The symbol of the SPL Token (e.g., 'USDC', 'RAY').
-
network
'mainnet-beta' | 'devnet'
The network to use for resolving the token symbol to a mint address.
-

Response

NameTypeDefault
success
boolean
Indicates if the balance was fetched successfully. If `false`, check the `error` property.
balance
Balance
An object containing balance details if successful, otherwise `null`.
null
error
string | undefined
An error message if the operation failed.
-

Balance

If the success flag is true, the balance property will contain an object with the following structure.

NameTypeDefault
amount
string
The raw token balance as a string, without accounting for decimals. e.g., '1500000'.
'0'
decimals
number
The number of decimals for this token mint. e.g., 6.
0
uiAmount
number | null
The token balance as a floating-point number, with decimals applied. Can be inaccurate for very large numbers.
null
uiAmountString
string | undefined
A string representation of the token balance, with decimals applied. e.g., '1.5'. This is the safest and most precise value to use for display purposes.
undefined
Last updated on