Skip to Content
FunctionsTokengetTokenBalanceByMint

getTokenBalanceByMint

This function fetches the SPL token balance for a given wallet and mint.

Usage

page.tsx
import { useConnection } from "@solana/wallet-adapter-react"; import { getTokenBalanceByMint } from "@okito/sdk"; const {connection} = useConnection(); const mintAddress = ""; //mint address for the token const target = ""; // the account for which balance is requested const tokenBalance = await getTokenBalanceByMint(connection,target,mintAddress)

Capabilities

  • Works whether the ATA exists or not
  • Returns decimals and formatted values
  • Clear error messages when lookups fail

Props

NameTypeDefault
Connection
Connection
The connection object to the blockchain.
—
target
PublicKey | string
The address of the account for which balance is being retrieved.
—
mint
string
Mint address of the token being used.
—

Response

NameTypeDefault
balance
Balance
The balance object containing token amount and formatting details, or null if not available.
null
success
boolean
Indicates if the request was successful.
—
error
string | undefined
Error message if the request failed.
undefined

Balance

NameTypeDefault
amount
string
The amount of the tokens present without accounting for decimals.
—
decimals
number
The number of decimals that the token possesses.
—
uiAmount
number | null
The number of tokens present, accounting for decimals.
—
uiAmountString
string | undefined
The number of tokens present, accounting for decimals, in string format.
—
Last updated on