helius_get_latest_blockhash
Retrieve the current blockhash from Solana for constructing transactions.
Instructions
Get the latest blockhash from the Solana blockchain
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "helius_get_latest_blockhash"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commitment | No |
Implementation Reference
- src/handlers/helius.ts:128-135 (handler)Handler function that calls connection.getLatestBlockhash() and returns the blockhash and last valid block height.
export const getLatestBlockhashHandler = async (input: GetLatestBlockhashInput): Promise<ToolResultSchema> => { try { const { blockhash, lastValidBlockHeight } = await (helius as any as Helius).connection.getLatestBlockhash(input.commitment); return createSuccessResponse(`Latest blockhash: ${blockhash}, Last valid block height: ${lastValidBlockHeight}`); } catch (error) { return createErrorResponse(`Error getting latest blockhash: ${error instanceof Error ? error.message : String(error)}`); } } - src/handlers/helius.types.ts:56-63 (schema)Type definitions for GetLatestBlockhashInput (optional commitment) and GetLatestBlockhashOutput (blockhash + lastValidBlockHeight).
export type GetLatestBlockhashInput = { commitment?: "confirmed" | "finalized" | "processed"; } export type GetLatestBlockhashOutput = { blockhash: string; lastValidBlockHeight: number; } - src/tools.ts:91-101 (registration)Tool registration defining the name, description, and input schema for helius_get_latest_blockhash.
{ name: "helius_get_latest_blockhash", description: "Get the latest blockhash from the Solana blockchain", inputSchema: { type: "object", properties: { commitment: { type: "string", enum: ["confirmed", "finalized", "processed"] } }, required: [] } }, - src/tools.ts:555-555 (registration)Mapping the tool name string to its handler function in the handlers dictionary.
"helius_get_latest_blockhash": getLatestBlockhashHandler, - src/handlers/utils.ts:38-59 (helper)Utility functions createSuccessResponse and createErrorResponse used by the handler to format responses.
export const createSuccessResponse = (message: string): ToolResultSchema => { return { content: [{ type: "text", text: message }], isError: false }; }; /** * Utility function to validate a public key and return an error response if invalid * @param publicKeyString The public key string to validate * @returns Either a PublicKey object or a ToolResultSchema with an error message */ export const validatePublicKey = (publicKeyString: string): PublicKey | ToolResultSchema => { const { publicKey, error } = createPublicKey(publicKeyString); if (error) { return createErrorResponse(error); } return publicKey!; };