Skip to main content
Glama

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
NameRequiredDescriptionDefault
publicKeyYes
programIdYes

Implementation Reference

  • 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)}`);
      }
    }
  • 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,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dcSpark/mcp-server-helius'

If you have feedback or need assistance with the MCP directory API, please join our Discord server