get_token_accounts
Retrieve all token accounts associated with a specific Solana wallet to view holdings and manage assets.
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 handler function that implements the core logic of the 'get_token_accounts' tool. It retrieves all SPL token accounts owned by the specified wallet using Solana's RPC connection.getTokenAccountsByOwner method, parses the results, and returns a list of token accounts with their addresses, mints, balances, 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 (registration)The tool registration entry in the tools array, which defines the name, description, and input schema for 'get_token_accounts'. This is returned by the ListToolsRequestHandler.{ 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:292-301 (schema)The input schema for the 'get_token_accounts' tool, defining that it requires a 'walletName' string parameter.inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet" } }, required: ["walletName"] }
- src/index.ts:1327-1329 (registration)The dispatch case in the main CallToolRequestSchema handler that routes calls to the 'get_token_accounts' tool to its handler function.case "get_token_accounts": result = await handleGetTokenAccounts(args); break;