Skip to main content
Glama

get_transaction

Retrieve detailed Bitcoin transaction information by providing a transaction ID. Use this tool to access real-time blockchain data from the mempool.space API.

Instructions

Get transaction details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
txidYesTransaction ID

Implementation Reference

  • The handler function that implements the core logic of the 'get-transaction' tool. It retrieves the transaction data using the helper, formats it nicely, and returns a text response.
    async ({ txid }) => { try { const tx = await getTransaction(txid); let result = `**Transaction: ${tx.txid}**\n\n`; result += `**Basic Info:**\n`; result += `- Version: ${tx.version}\n`; result += `- Size: ${tx.size} bytes\n`; result += `- Weight: ${tx.weight} WU\n`; result += `- Fee: ${tx.fee} sats\n`; result += `- Locktime: ${tx.locktime}\n\n`; result += `**Status:**\n`; if (tx.status.confirmed) { result += `- Confirmed in block ${tx.status.block_height}\n`; result += `- Block hash: ${tx.status.block_hash}\n`; result += `- Block time: ${new Date(tx.status.block_time! * 1000).toISOString()}\n`; } else { result += `- Unconfirmed (in mempool)\n`; } result += "\n"; result += `**Inputs (${tx.vin.length}):**\n`; tx.vin.forEach((input, index) => { if (input.prevout) { result += `${index + 1}. ${input.txid.substring(0, 16)}...:${input.vout} - ${(input.prevout.value / 100000000).toFixed(8)} BTC\n`; } else { result += `${index + 1}. Coinbase transaction\n`; } }); result += "\n"; result += `**Outputs (${tx.vout.length}):**\n`; tx.vout.forEach((output, index) => { result += `${index + 1}. ${(output.value / 100000000).toFixed(8)} BTC to ${output.scriptpubkey_address || "Unknown address"}\n`; }); return { content: [ { type: "text", text: result, }, ], }; } catch (error: any) { return { content: [ { type: "text", text: `Error fetching transaction data: ${error.message || "Unknown error"}`, }, ], }; } },
  • Supporting helper utility that performs the actual API call to fetch raw transaction data from mempool.space.
    async function getTransaction(txid: string): Promise<Transaction> { const res = await superagent .get(`${MEMPOOL_API_BASE}/tx/${txid}`) .set("User-Agent", USER_AGENT); return res.body; }
  • Input schema using Zod to validate the 'txid' parameter.
    { txid: z.string().describe("Transaction ID (hash) to query"), },
  • src/index.ts:262-324 (registration)
    Registration of the tool with MCP server using server.tool, including name, description, input schema, and handler.
    server.tool( "get-transaction", "Get detailed information about a Bitcoin transaction", { txid: z.string().describe("Transaction ID (hash) to query"), }, async ({ txid }) => { try { const tx = await getTransaction(txid); let result = `**Transaction: ${tx.txid}**\n\n`; result += `**Basic Info:**\n`; result += `- Version: ${tx.version}\n`; result += `- Size: ${tx.size} bytes\n`; result += `- Weight: ${tx.weight} WU\n`; result += `- Fee: ${tx.fee} sats\n`; result += `- Locktime: ${tx.locktime}\n\n`; result += `**Status:**\n`; if (tx.status.confirmed) { result += `- Confirmed in block ${tx.status.block_height}\n`; result += `- Block hash: ${tx.status.block_hash}\n`; result += `- Block time: ${new Date(tx.status.block_time! * 1000).toISOString()}\n`; } else { result += `- Unconfirmed (in mempool)\n`; } result += "\n"; result += `**Inputs (${tx.vin.length}):**\n`; tx.vin.forEach((input, index) => { if (input.prevout) { result += `${index + 1}. ${input.txid.substring(0, 16)}...:${input.vout} - ${(input.prevout.value / 100000000).toFixed(8)} BTC\n`; } else { result += `${index + 1}. Coinbase transaction\n`; } }); result += "\n"; result += `**Outputs (${tx.vout.length}):**\n`; tx.vout.forEach((output, index) => { result += `${index + 1}. ${(output.value / 100000000).toFixed(8)} BTC to ${output.scriptpubkey_address || "Unknown address"}\n`; }); return { content: [ { type: "text", text: result, }, ], }; } catch (error: any) { return { content: [ { type: "text", text: `Error fetching transaction data: ${error.message || "Unknown error"}`, }, ], }; } }, );
  • Type definition for the Transaction object used in the tool.
    type Transaction = { txid: string; version: number; locktime: number; vin: any[]; vout: any[]; size: number; weight: number; fee: number; status: { confirmed: boolean; block_height?: number; block_hash?: string; block_time?: number; }; };

Other Tools

Related Tools

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/JamesANZ/bitcoin-mcp'

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