HTLC (Hashed Time-Locked Contract)
A mechanism requiring a secret (preimage) to unlock payment before a time lock expires, core to LN and atomic swaps.
A Hashed Time-Locked Contract (HTLC) is a Bitcoin script that locks funds with two conditions: spendable by the intended receiver if they reveal a secret value (the preimage of a known hash) and sign with their own key, OR refundable to the sender if a time deadline passes without that secret being revealed. The signature check is not decoration. A revealed preimage says nothing about who should be paid, so without it anyone who saw the secret could claim the funds.
In script form, roughly:
IF hash(provided value) == target_hash AND signed by receiver THEN
pay to receiver
ELSE IF current_time > deadline AND signed by sender THEN
pay back to sender
END
This deceptively simple structure is the foundation of trustless multi-party Bitcoin protocols.
Why HTLCs are so useful:
- Lightning Network routing. When you pay across multiple Lightning hops, each hop is bound by an HTLC. The receiver knows the secret. They claim from the previous hop by revealing it. That hop claims from the one before by passing on the same secret. Backward up the chain, every hop gets paid atomically as the secret propagates. Either the whole payment succeeds, or it all unwinds when the timeouts hit.
- Atomic swaps. Two parties on different chains can swap coins without trusting each other. Each side locks funds in an HTLC. Whoever first reveals the secret claims their funds and exposes the secret, letting the other party claim theirs. If anyone bails, both refunds trigger at the deadline.
- Submarine swaps. Swap on-chain BTC for Lightning BTC (or vice versa) through a swap provider. Both legs pay the same HTLC, so the provider cannot collect one side without releasing the other.
The "time-locked" part isn't optional. Without a deadline, funds could be stuck forever waiting for a secret that may never be revealed. The deadline ensures that something happens - either the payment completes (secret revealed) or it doesn't (refund triggers). Time itself becomes part of the security model.
HTLCs are the primitive that makes Bitcoin's layer-2 ecosystem trust-minimized rather than trust-based. The idea of a payment locked by a hash and limited by a clock goes back at least to forum posts from 2012, and every routed Lightning payment has depended on it since the first mainnet releases in 2018. A routing node can refuse to forward a payment, but it cannot take the money.
See Payment Points for the PTLC successor concept: same atomicity, same time-lock guarantees, but the hash-and-preimage lock is replaced by an elliptic-curve point and scalar. PTLCs can use less block space, and because every hop can use a different point, routing nodes can no longer match up the hops of one payment. Taproot brought the Schnorr signatures they need; Lightning still runs on HTLCs, and the move to PTLCs remains an open upgrade discussion.
Key takeaways
- Enables trust-minimized payment and swaps
- Uses a hash puzzle + time lock for safe fallback
- Foundation of LN's multi-hop payment logic
Related chapters
Corrected
-
Was: The entry said an HTLC's funds are spendable by anyone who reveals the preimage, and its script sketch showed a claim path with no signature check.
Now: The claim path is bound to the intended receiver's key as well as the preimage; a revealed preimage alone identifies nobody, so without the signature check anyone who saw it could take the funds. The script sketch now shows the receiver's signature on the claim path and the sender's on the refund path. Details
Sources (6)
- BIP 199 - Hashed Time-Locked Contract transactions (2017)
- Bitcoin Optech - Hash Time Locked Contract (HTLC) topic (accessed 2026-10-13)
- Joseph Poon and Thaddeus Dryja - The Bitcoin Lightning Network: Scalable Off-Chain Instant Payments, section 4, Hashed Timelock Contract (2016)
- Bitcoin Optech - Submarine swaps topic (accessed 2026-10-13)
- Bitcoin Optech - Point Time Locked Contracts (PTLCs) topic (accessed 2026-10-13)
- Lightning Labs - Announcing our first Lightning mainnet release, lnd 0.4-beta (2018-03-15)
External references (2)
Related terms (25)
- Atomic Multi-Path Payment (AMP)
- Atomic Swap
- Atomic Swap Refill
- BOLT 11
- Bridge Node (Lightning)
- CheckLockTimeVerify (CLTV)
- Eltoo
- Escrow
- Escrowed Lightning Channel
- Fraud Proof
- Fraudulent Channel Close
- Griefing Attack
- Hash Puzzle
- HTLC Invoice
- HTLC Preimage Manager
- Lightning Channel
- Lightning Channel Splicing
- Lightning Network
- Lightning Payment
- Lightning Routing
- Payment Channel
- Payment Point
- Routing Node
- Submarine Swap
- Time-Locked Contract
Published . Revised . One correction logged for this page.
Edit this page on GitHub