helius_get_token_accounts_by_owner
Retrieve token accounts associated with a Solana wallet address to view holdings and manage assets on the blockchain.
Instructions
Get token accounts owned by a Solana address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| publicKey | Yes | ||
| programId | Yes |
Implementation Reference
- src/handlers/helius.ts:73-94 (handler)The handler function that validates inputs, calls the Solana RPC getTokenAccountsByOwner via Helius connection, and formats the response with token account pubkeys.export const getTokenAccountsByOwnerHandler = async (input: GetTokenAccountsByOwnerInput): Promise<ToolResultSchema> => { const ownerPublicKeyResult = validatePublicKey(input.publicKey); if (!(ownerPublicKeyResult instanceof PublicKey)) { return ownerPublicKeyResult; } const programIdResult = validatePublicKey(input.programId); if (!(programIdResult instanceof PublicKey)) { return programIdResult; } try { const tokenAccounts = await (helius as any as Helius).connection.getTokenAccountsByOwner(ownerPublicKeyResult, { programId: programIdResult, }); return createSuccessResponse(` Context: ${tokenAccounts.context.slot} Token accounts: ${tokenAccounts.value.map((tokenAccount) => tokenAccount.pubkey.toString()).join("\n")}`); } catch (error) { return createErrorResponse(`Error getting token accounts: ${error instanceof Error ? error.message : String(error)}`); } }
- src/tools.ts:56-67 (schema)Tool schema definition including name, description, and input schema requiring publicKey (owner) and programId.{ name: "helius_get_token_accounts_by_owner", description: "Get token accounts owned by a Solana address", inputSchema: { type: "object", properties: { publicKey: { type: "string" }, programId: { type: "string" } }, required: ["publicKey", "programId"] } },
- src/tools.ts:552-552 (registration)Maps the tool name to its handler function in the handlers dictionary for tool dispatching."helius_get_token_accounts_by_owner": getTokenAccountsByOwnerHandler,