get_token_accounts
Retrieve all token accounts associated with a specific wallet to view token holdings and balances on the Solana blockchain.
Instructions
Get all token accounts for a wallet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| walletName | Yes | Name of the wallet |
Implementation Reference
- src/index.ts:872-900 (handler)The main handler function for the 'get_token_accounts' tool. It retrieves all SPL token accounts owned by the specified wallet using Solana RPC connection.getTokenAccountsByOwner, parses the results, and returns a list of token accounts with their addresses, mints, amounts, and decimals.async function handleGetTokenAccounts(args: any) { const { walletName } = args; const wallet = wallets.get(walletName); if (!wallet) { throw new Error(`Wallet '${walletName}' not found`); } ensureConnection(); const tokenAccounts = await connection.getTokenAccountsByOwner(wallet.keypair.publicKey, { programId: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") }); const accounts = tokenAccounts.value.map(account => { const data = account.account.data as any; return { address: account.pubkey.toString(), mint: data.parsed?.info?.mint || 'unknown', amount: data.parsed?.info?.tokenAmount?.uiAmount || 0, decimals: data.parsed?.info?.tokenAmount?.decimals || 0 }; }); return { wallet: walletName, tokenAccounts: accounts, count: accounts.length }; }
- src/index.ts:289-302 (schema)Input schema definition for the 'get_token_accounts' tool, specifying the required 'walletName' parameter.{ name: "get_token_accounts", description: "Get all token accounts for a wallet", inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet" } }, required: ["walletName"] } },
- src/index.ts:1327-1329 (registration)Tool registration in the main CallToolRequestSchema handler's switch statement, dispatching to the handleGetTokenAccounts function.case "get_token_accounts": result = await handleGetTokenAccounts(args); break;