HTLC
Also: Hash Time Locked Contract
lightning · advanced
A payment that's redeemable by revealing a preimage before a deadline. The primitive Lightning uses to route multi-hop payments trustlessly.
A Hash Time-Locked Contract is a conditional payment with two clauses:
1. Pay the recipient if they can produce the preimage of a specific hash before block N.
2. Refund the sender if no preimage is revealed by block N.
That's it. Bitcoin Script can express this directly with OP_HASH160 and OP_CHECKLOCKTIMEVERIFY (or via Tapscript on modern channels).
The magic is what happens when you chain them. Say Alice wants to pay Eve through Bob and Carol. Eve generates a random secret S, sends Alice the hash H(S), and Alice constructs the route by setting up HTLCs along the way:
- Alice → Bob: "I'll pay 100 sats if you reveal preimage of H, within 3 hours."
- Bob → Carol: "I'll pay 99 sats if you reveal preimage of H, within 2 hours."
- Carol → Eve: "I'll pay 98 sats if you reveal preimage of H, within 1 hour."
Eve claims Carol's HTLC by revealing S, which lets Carol claim Bob's HTLC by revealing S, which lets Bob claim Alice's. The preimage propagates backwards atomically — either the whole route settles or none of it does. The timeouts cascade so a middle hop can never get stuck holding a one-sided obligation.