
Decode Lightning Invoices in Pure Python — No Node Required
Ever wanted to decode a BOLT11 Lightning invoice without running a node? Here's how in pure Python — no lnd, no c-lightning, no external APIs. Quick Usage from ln_invoice_decode import decode_invoice info = decode_invoice ( " lnbc100n1p... " ) print ( f " Amount: { info [ ' amount_sats ' ] } sats " ) print ( f " Description: { info [ ' description ' ] } " ) print ( f " Expired: { info [ ' is_expired ' ] } " ) Or from CLI: python ln_invoice_decode.py lnbc100n1pn... # ⚡ Lightning Invoice # Amount: 100 sats # Network: mainnet # Status: ✅ Valid How BOLT11 Works A Lightning invoice is just bech32-encoded data with a human-readable part (HRP) and tagged fields. 1. HRP = Network + Amount lnbc100n → ln + bc (mainnet) + 100n (100 nanobitcoin = 100 sats) Multipliers: m (milli), u (micro), n (nano), p (pico) 2. Timestamp (35 bits) First 7 groups of 5-bit values = Unix timestamp of invoice creation. 3. Tagged Fields Each field: tag (5 bits) + length (10 bits) + data p → payment hash (32 bytes) d →
Continue reading on Dev.to Tutorial
Opens in a new tab


