get_transaction
Retrieve VeChain blockchain transaction details by ID, with options to include pending transactions, raw hex data, or pin to specific blocks.
Instructions
Get a VeChain transaction by its ID. Optionally include pending txs (meta may be null), return raw hex, or pin to a specific head block.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Transaction ID (0x-prefixed 32-byte hex) | |
| pending | No | Include pending transactions (meta may be null). Default: false | |
| raw | No | Include raw hex transaction in response. Default: false | |
| head | No | Head block ID to use; defaults to best if omitted |
Implementation Reference
- src/tools.ts:211-292 (handler)Handler function that implements the get_transaction tool logic: constructs Thorest API URL for /transactions/{id}, adds query params, fetches with timeout, parses JSON, handles errors and not found cases, returns formatted content.callback: async ({ id, pending = false, raw = false, head }: { id: string, pending?: boolean, raw?: boolean, head?: string }) => { const base = isMainnet ? vechainConfig.mainnet.thorestApiBaseUrl : vechainConfig.testnet.thorestApiBaseUrl; const path = `/transactions/${encodeURIComponent(id)}`; const qs = new URLSearchParams(); if (typeof pending === "boolean") qs.set("pending", String(pending)); if (typeof raw === "boolean") qs.set("raw", String(raw)); if (head) qs.set("head", head); const url = `${base}${path}${qs.toString() ? `?${qs.toString()}` : ""}`; const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), isMainnet ? vechainConfig.mainnet.controllerAbortTimeout : vechainConfig.testnet.controllerAbortTimeout); try { const res = await fetch(url, { signal: controller.signal }); if (!res.ok) { const bodyText = await res.text().catch(() => ""); throw new Error( `VeChain node responded ${res.status} ${res.statusText}${bodyText ? `: ${bodyText}` : "" }` ); } const data = await res.json(); if (data == null) { return { content: [ { type: "text", text: JSON.stringify( { message: "Transaction not found", id, pending, raw, head: head ?? "best", }, null, 2 ), }, ], }; } return { content: [ { type: "text", text: JSON.stringify(data, null, 2), }, ], }; } catch (err) { const isAbort = (err as Error)?.name === "AbortError"; return { content: [ { type: "text", text: JSON.stringify( { error: isAbort ? "Request timed out" : "Failed to fetch transaction", reason: String((err as Error)?.message ?? err), url, id, pending, raw, head: head ?? "best", }, null, 2 ), }, ], }; } finally { clearTimeout(timeout); } }
- src/tools.ts:193-210 (schema)Input schema using Zod for validating tool parameters: id (tx ID regex), pending (bool opt), raw (bool opt), head (string opt).inputSchema: { id: z .string() .regex(vechainConfig.general.txidRegex, "Invalid transaction ID: expected 0x + 64 hex chars") .describe("Transaction ID (0x-prefixed 32-byte hex)"), pending: z .boolean() .optional() .describe("Include pending transactions (meta may be null). Default: false"), raw: z .boolean() .optional() .describe("Include raw hex transaction in response. Default: false"), head: z .string() .optional() .describe("Head block ID to use; defaults to best if omitted"), },
- src/server.ts:74-92 (registration)Registration of all vechainTools (including get_transaction) by looping and calling server.registerTool with name, description, inputSchema from tool def, and a wrapper async handler that calls the tool's callback and normalizes response content type.for (const t of vechainTools) { server.registerTool( t.name, { title: t.name, description: t.description, inputSchema: t.inputSchema }, async (args) => { const result = await t.callback(args); return { content: result.content.map(item => ({ ...item, type: "text" as const })) }; } ); }