helius_get_program_accounts
Retrieve all accounts owned by a specific Solana program using its program ID.
Instructions
Get all accounts owned by a program
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| programId | Yes | ||
| commitment | No |
Implementation Reference
- src/handlers/helius.ts:193-205 (handler)The handler function for 'helius_get_program_accounts'. It validates the programId input, then calls connection.getProgramAccounts() and returns the result.
export const getProgramAccountsHandler = async (input: GetProgramAccountsInput): Promise<ToolResultSchema> => { const programIdResult = validatePublicKey(input.programId); if (!(programIdResult instanceof PublicKey)) { return programIdResult; } try { const programAccounts = await (helius as any as Helius).connection.getProgramAccounts(programIdResult, input.commitment); return createSuccessResponse(`Program accounts: ${JSON.stringify(programAccounts, null, 2)}`); } catch (error) { return createErrorResponse(`Error getting program accounts: ${error instanceof Error ? error.message : String(error)}`); } } - src/handlers/helius.types.ts:101-104 (schema)Type definition for GetProgramAccountsInput with programId (string) and optional commitment enum.
export type GetProgramAccountsInput = { programId: string; commitment?: "confirmed" | "finalized" | "processed"; } - src/tools.ts:150-160 (registration)Tool registration with name 'helius_get_program_accounts', description, and inputSchema (programId required, optional commitment).
{ name: "helius_get_program_accounts", description: "Get all accounts owned by a program", inputSchema: { type: "object", properties: { programId: { type: "string" }, commitment: { type: "string", enum: ["confirmed", "finalized", "processed"] } }, required: ["programId"] } - src/tools.ts:561-561 (registration)Handler mapping in the handlers dictionary, mapping 'helius_get_program_accounts' to getProgramAccountsHandler.
"helius_get_program_accounts": getProgramAccountsHandler, - src/handlers/utils.ts:9-16 (helper)Utility function createPublicKey (though the handler uses validatePublicKey) for validating public keys.
export const createPublicKey = (publicKeyString: string): { publicKey?: PublicKey; error?: string } => { try { const publicKey = new PublicKey(publicKeyString); return { publicKey }; } catch (error) { return { error: `Invalid public key: ${publicKeyString}` }; } };