Skip to main content
Glama

get_transaction

Retrieve VeChain blockchain transaction details by ID, with options for pending transactions, raw hex data, and specific block references.

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
NameRequiredDescriptionDefault
idYesTransaction ID (0x-prefixed 32-byte hex)
pendingNoInclude pending transactions (meta may be null). Default: false
rawNoInclude raw hex transaction in response. Default: false
headNoHead block ID to use; defaults to best if omitted

Implementation Reference

  • The handler function for the 'get_transaction' tool. It constructs the Thorest API URL for /transactions/{id} with optional query parameters (pending, raw, head), performs a fetch request with timeout and abort control, handles errors, and returns the transaction data as JSON or an error message.
    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);
        }
    }
  • Zod input schema for validating the parameters of the get_transaction tool: transaction ID (required), pending, raw, and head (all optional).
    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/tools.ts:189-293 (registration)
    The registration of the 'get_transaction' tool within the vechainTools array, including name, title, description, inputSchema, and callback handler.
    {
        name: "get_transaction",
        title: "Retrieve a transaction by ID",
        description: "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.",
        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"),
        },
        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);
            }
        }
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/leandrogavidia/vechain-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server