Skip to content

A Rust-based command-line tool that decodes a raw Bitcoin transaction hex and outputs a structured JSON view of the transaction.

License

Notifications You must be signed in to change notification settings

TH3BAT/transaction-decoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Transaction Decoder

A Rust-based command-line tool that decodes a raw Bitcoin transaction hex and outputs a structured JSON view of the transaction.

This tool is intentionally offline-friendly and index-free: it decodes Bitcoin transactions directly from their serialized bytes, following consensus rules—no RPC calls, no explorers, no lookup tables.

Why This Exists

Bitcoin transactions are not opaque objects that require external services to understand. They are deterministic binary messages.

This tool exists to make that reality obvious.

Features

  • Raw Transaction Decoding Decodes a full serialized Bitcoin transaction directly from raw hex bytes.

  • Consensus-Accurate Parsing Implements Bitcoin’s consensus encoding rules:

    • little-endian integers
    • CompactSize (varint) encoding
    • legacy and SegWit transaction formats
  • TxID & wTxID Calculation

    • Computes the legacy txid (double SHA-256, no witness)
    • Computes wtxid for SegWit transactions (includes witness data)
  • Structured JSON Output Outputs a clean, human-readable JSON view:

    • inputs / outputs
    • scripts (hex)
    • values (sats + BTC string, no floats)
    • witness data (when present)
  • Clear Error Reporting Explicit errors for:

    • invalid hex
    • truncated or malformed transactions
    • invalid SegWit flags
    • trailing bytes after decode
  • TxID Detection Guardrail If a 64-hex-character string is provided, the tool warns that it appears to be a txid, not raw transaction data.

Non-Goals

This tool deliberately does not:

  • fetch transactions by txid
  • query Bitcoin Core or any external service
  • depend on indexes, explorers, or databases

It decodes only what you already have.

Prerequisites

  • Rust (stable, current)

Installation

Clone the repository and build:

git clone https://github.com/th3bat/transaction-decoder.git
cd transaction-decoder
cargo build --release

Usage

Provide a raw Bitcoin transaction hex (optionally 0x-prefixed):

./target/release/transaction-decoder "<raw_transaction_hex>"

Example:

./target/release/transaction-decoder \
"02000000000101e1b5...00000000"

Common Mistake

If you pass a txid (32 bytes / 64 hex characters), the program will respond with:

That looks like a txid.
This decoder expects raw transaction hex.

You must supply the full serialized transaction, not its hash.

Output

The program prints a pretty-formatted JSON representation including:

  • txid
  • wtxid (when applicable)
  • transaction version and locktime
  • inputs (prevout, scriptSig, sequence, witness)
  • outputs (value in sats and BTC, scriptPubKey)

Philosophy

Bitcoin’s protocol does not rely on:

  • databases
  • indexes
  • REST APIs

It relies on:

  • bytes
  • ordering
  • hashing
  • rules that never change

This tool is a small reminder of that.

About

A Rust-based command-line tool that decodes a raw Bitcoin transaction hex and outputs a structured JSON view of the transaction.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages