helius_get_token_accounts_by_owner
Retrieve Solana token accounts associated with a specific address using the Helius API to interact with blockchain data and manage token operations.
Instructions
Get token accounts owned by a Solana address
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| programId | Yes | ||
| publicKey | Yes |
Input Schema (JSON Schema)
{
"properties": {
"programId": {
"type": "string"
},
"publicKey": {
"type": "string"
}
},
"required": [
"publicKey",
"programId"
],
"type": "object"
}
Implementation Reference
- src/handlers/helius.ts:73-94 (handler)The handler function that validates the owner and programId public keys, then calls the Solana RPC method getTokenAccountsByOwner via the Helius client.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)The input schema defining the parameters: publicKey (owner) and programId for the tool.{ 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)Registration mapping the tool name to its handler function in the handlers dictionary."helius_get_token_accounts_by_owner": getTokenAccountsByOwnerHandler,