get_transaction_status
Check the status and details of an Aptos Blockchain transaction using its hash. Verify transaction success and retrieve comprehensive information for analysis.
Instructions
Get the status and details of a transaction by its hash. This is used for checking if a transaction was successful and getting detailed information about it. Returns comprehensive transaction information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| transaction_hash | Yes | Transaction hash to check, e.g., 0x1234567890abcdef... |
Implementation Reference
- Main handler function that validates input arguments, calls the core performance function, and returns a formatted MCP response (success or error).export async function getTransactionStatusHandler(args: Record<string, any> | undefined) { if (!isGetTransactionStatusArgs(args)) { throw new Error("Invalid arguments for get_transaction_status"); } const { transaction_hash } = args; try { const results = await performGetTransactionStatus(transaction_hash); return { content: [{ type: "text", text: results }], isError: false, }; } catch (error) { return { content: [ { type: "text", text: `Error getting transaction status: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }
- Tool schema defining name, description, and input schema requiring a transaction_hash string.export const GET_TRANSACTION_STATUS: Tool = { name: "get_transaction_status", description: "Get the status and details of a transaction by its hash. This is used for checking if a transaction was successful and getting detailed information about it. Returns comprehensive transaction information.", inputSchema: { type: "object", properties: { transaction_hash: { type: "string", description: "Transaction hash to check, e.g., 0x1234567890abcdef...", }, }, required: ["transaction_hash"], }, };
- Core helper function that queries the Aptos client for transaction details by hash, handles pending and committed transactions, extracts and formats information like success status, gas usage, payload, events, and errors.export async function performGetTransactionStatus(transactionHash: string): Promise<string> { try { const aptos = getAptosClient(); // Get transaction details const transaction = await aptos.getTransactionByHash({ transactionHash }); let result = `Transaction Status: Hash: ${transaction.hash}`; // Check if this is a committed transaction (not pending) if (transaction.type !== 'pending_transaction') { result += ` Version: ${transaction.version} Success: ${transaction.success ? '✅ Success' : '❌ Failed'} Gas Used: ${transaction.gas_used} VM Status: ${transaction.vm_status}`; } else { result += ` Status: ⏳ Pending`; } // Add additional information for committed transactions if (transaction.type !== 'pending_transaction') { // Add sender information if available if ('sender' in transaction) { result += ` Sender: ${formatAddress(transaction.sender)}`; } // Add sequence number if available if ('sequence_number' in transaction) { result += ` Sequence Number: ${transaction.sequence_number}`; } // Add max gas amount if available if ('max_gas_amount' in transaction) { result += ` Max Gas Amount: ${transaction.max_gas_amount}`; } // Add gas unit price if available if ('gas_unit_price' in transaction) { result += ` Gas Unit Price: ${transaction.gas_unit_price}`; } // Add timestamp if available if ('timestamp' in transaction) { const date = new Date(parseInt(transaction.timestamp) / 1000); result += ` Timestamp: ${date.toISOString()}`; } } // Add payload information if available (only for committed transactions) if (transaction.type !== 'pending_transaction' && 'payload' in transaction && transaction.payload) { result += ` Payload Information: Type: ${transaction.payload.type}`; if (transaction.payload.type === 'entry_function_payload' && 'function' in transaction.payload) { result += ` Function: ${transaction.payload.function}`; if ('type_arguments' in transaction.payload && transaction.payload.type_arguments && transaction.payload.type_arguments.length > 0) { result += ` Type Arguments: ${transaction.payload.type_arguments.join(', ')}`; } if ('arguments' in transaction.payload && transaction.payload.arguments && transaction.payload.arguments.length > 0) { result += ` Arguments: ${transaction.payload.arguments.join(', ')}`; } } } // Add events information if available (only for committed transactions) if (transaction.type !== 'pending_transaction' && 'events' in transaction && transaction.events && transaction.events.length > 0) { result += ` Events (${transaction.events.length}):`; transaction.events.slice(0, 5).forEach((event, index) => { result += ` ${index + 1}. Type: ${event.type}`; if (event.data) { result += ` Data: ${JSON.stringify(event.data)}`; } }); if (transaction.events.length > 5) { result += ` ... and ${transaction.events.length - 5} more events`; } } return result; } catch (error) { console.error('Error getting transaction status:', error); if (error instanceof Error && error.message.includes('not found')) { return `Transaction Status: Hash: ${transactionHash} Status: ❌ Transaction not found Note: Transaction may not exist or may not have been processed yet`; } throw new Error(`Failed to get transaction status: ${error instanceof Error ? error.message : String(error)}`); } }
- Type guard function to validate that arguments contain a valid transaction_hash string.export function isGetTransactionStatusArgs(args: unknown): args is { transaction_hash: string } { return ( typeof args === "object" && args !== null && "transaction_hash" in args && typeof (args as any).transaction_hash === "string" ); }
- src/index.ts:138-139 (registration)Tool call dispatch in the main stdio MCP server switch statement.case "get_transaction_status": return await getTransactionStatusHandler(args);