helius_get_balance
Retrieve the Solana wallet balance for a specified public key using the Helius API. Supports querying confirmed, finalized, or processed transaction states.
Instructions
Get the balance of a Solana address
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commitment | No | ||
| publicKey | Yes |
Input Schema (JSON Schema)
{
"properties": {
"commitment": {
"enum": [
"confirmed",
"finalized",
"processed"
],
"type": "string"
},
"publicKey": {
"type": "string"
}
},
"required": [
"publicKey"
],
"type": "object"
}
Implementation Reference
- src/handlers/helius.ts:47-62 (handler)Main handler function implementing the helius_get_balance tool logic using Helius SDK to fetch account balance.export const getBalanceHandler = async (input: GetBalanceInput): Promise<ToolResultSchema> => { try { // Validate the public key is a valid format const publicKey = validatePublicKey(input.publicKey); if (!(publicKey instanceof PublicKey)) { return publicKey; } // Remove the test mode check since we want to use the mock implementation const balance = await (helius as any as Helius).connection.getBalance(publicKey, input.commitment); return createSuccessResponse(`Balance: ${balance} lamports (${balance / LAMPORTS_PER_SOL} SOL)`); } catch (error) { return createErrorResponse(`Error getting balance: ${error instanceof Error ? error.message : String(error)}`); } }
- src/tools.ts:33-44 (schema)Input schema definition for the helius_get_balance tool in the tools registry.{ name: "helius_get_balance", description: "Get the balance of a Solana address", inputSchema: { type: "object", properties: { publicKey: { type: "string" }, commitment: { type: "string", enum: ["confirmed", "finalized", "processed"] } }, required: ["publicKey"] } },
- src/tools.ts:550-550 (registration)Maps the tool name 'helius_get_balance' to its handler function getBalanceHandler in the handlers dictionary."helius_get_balance": getBalanceHandler,
- src/handlers/helius.types.ts:3-6 (schema)TypeScript type definition for the input of getBalanceHandler, matching the tool's inputSchema.export type GetBalanceInput = { publicKey: string; commitment?: "confirmed" | "finalized" | "processed"; }
- src/handlers/helius.ts:35-35 (helper)Imports helper functions used in the handler: validatePublicKey for input validation, createSuccessResponse and createErrorResponse for output formatting.import { createErrorResponse, createSuccessResponse, validatePublicKey } from "./utils.js";