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
| Name | Type | Default |
|---|---|---|
Connection | ConnectionThe connection object to the blockchain. | |
target | PublicKey | string The address of the account for which balance is being retrieved. | |
mint | stringMint address of the token being used. | |
Response
| Name | Type | Default |
|---|---|---|
balance | BalanceThe balance object containing token amount and formatting details, or null if not available. | |
success | booleanIndicates if the request was successful. | |
error | string | undefinedError message if the request failed. | |
Balance
| Name | Type | Default |
|---|---|---|
amount | stringThe amount of the tokens present without accounting for decimals. | |
decimals | numberThe number of decimals that the token possesses. | |
uiAmount | number | nullThe number of tokens present, accounting for decimals. | |
uiAmountString | string | undefinedThe number of tokens present, accounting for decimals, in string format. | |
Last updated on