Skip to Content
DocumentationTokensGet Token Accounts

Get Token Accounts

New in Kite 3.1.0

The getTokenAccounts function retrieves all token accounts owned by a wallet address. It searches both the SPL Token program and Token Extensions program, with an optional parameter to exclude zero-balance accounts.

Usage

const accounts = await connection.getTokenAccounts( walletAddress, excludeZeroBalance );

Parameters

  • walletAddress: Address - The wallet address to get token accounts for
  • excludeZeroBalance: boolean (optional) - If true, excludes token accounts with zero balance (default: false)

Returns

Returns a Promise<TokenAccount[]> containing an array of token accounts with the following properties:

  • address: Address of the token account
  • mint: Address of the token mint
  • owner: Owner of the token account
  • amount: Token balance in base units
  • decimals: Number of decimal places
  • program: Whether it’s from Token or Token Extensions program

Examples

Get all token accounts for a wallet:

import { address } from "@solana/kit"; const walletAddress = address("YourWalletAddressHere"); const allAccounts = await connection.getTokenAccounts(walletAddress); console.log(`Found ${allAccounts.length} token accounts`); allAccounts.forEach(account => { console.log(`Mint: ${account.mint}, Balance: ${account.amount}`); });

Get only token accounts with balances:

const activeAccounts = await connection.getTokenAccounts( walletAddress, true // exclude zero balance ); console.log(`Found ${activeAccounts.length} active token accounts`);

Use Cases

  • Portfolio management - Display all tokens owned by a wallet
  • Token cleanup - Find and close empty token accounts to reclaim rent
  • Airdrop eligibility - Check which tokens a wallet holds
  • Multi-token operations - Batch operations across multiple token accounts

Notes

  • Searches both SPL Token (legacy) and Token Extensions (Token-2022) programs
  • Returns accounts from both programs in a single array
  • The excludeZeroBalance parameter is useful for reducing API calls and filtering out closed or empty accounts
  • Token accounts are returned with their balances in base units (adjust for decimals when displaying)

See also: Get Token Account Address, Get Token Account Balance, Close Token Account

Last updated on