Skip to main content
Glama

decode_tx

Decode Bitcoin transaction data by inputting raw hexadecimal data to extract transaction details using the Bitcoin MCP Server. Simplify analysis of Bitcoin network activities.

Instructions

Decode a Bitcoin transaction

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rawHexYesTransaction hex

Implementation Reference

  • MCP tool handler for decode_tx: validates input with DecodeTxSchema, calls bitcoinService.decodeTx(rawHex), formats response as text content with TXID, version, input/output counts, locktime.
    export async function handleDecodeTx( bitcoinService: BitcoinService, args: unknown ) { const result = DecodeTxSchema.safeParse(args); if (!result.success) { throw new McpError( ErrorCode.InvalidParams, `Invalid parameters: ${result.error.message}` ); } const tx = bitcoinService.decodeTx(result.data.rawHex); return { content: [ { type: "text", text: `Decoded transaction:\nTXID: ${tx.txid}\nVersion: ${tx.version}\nInputs: ${tx.inputs.length}\nOutputs: ${tx.outputs.length}\nLocktime: ${tx.locktime}`, }, ] as TextContent[], }; }
  • Zod schema for decode_tx input validation: requires 'rawHex' as non-empty string.
    export const DecodeTxSchema = z.object({ rawHex: z.string().min(1, "Raw transaction hex is required"), });
  • Tool registration metadata in listToolsRequestHandler: name, description, inputSchema for decode_tx.
    name: "decode_tx", description: "Decode a Bitcoin transaction", inputSchema: { type: "object", properties: { rawHex: { type: "string", description: "Transaction hex" }, }, required: ["rawHex"], }, } as Tool,
  • Dispatch to handleDecodeTx in the CallToolRequestHandler switch statement.
    case "decode_tx": { return handleDecodeTx(this.bitcoinService, args); }
  • BitcoinService.decodeTx implementation: parses rawHex with bitcoinjs-lib Transaction.fromHex, extracts txid, version, inputs, outputs (with addresses), locktime; throws BitcoinError on failure.
    decodeTx(rawHex: string): DecodedTx { try { const tx = bitcoin.Transaction.fromHex(rawHex); return { txid: tx.getId(), version: tx.version, inputs: tx.ins.map((input) => ({ txid: Buffer.from(input.hash).reverse().toString("hex"), vout: input.index, sequence: input.sequence, })), outputs: tx.outs.map((output) => ({ value: output.value, scriptPubKey: output.script.toString("hex"), address: this.tryGetAddress(output.script), })), locktime: tx.locktime, }; } catch (error) { logger.error({ error, rawHex }, "Failed to decode transaction"); throw new BitcoinError( "Failed to decode transaction", BitcoinErrorCode.DECODE_ERROR ); } }

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

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