HTLC (Hash Time-Locked Contract)
By Menno — 13 years in crypto, 3 bear markets survived, zero paid promotions
Last updated: March 2026
AI Quick Summary: HTLC (Hash Time-Locked Contract) Summary
Term
HTLC (Hash Time-Locked Contract)
Category
Blockchain
Definition
A Hash Time-Locked Contract (HTLC) is a type of smart contract that releases funds only if the recipient provides a cryptographic preimage (the secret behind a hash) within a specified time window.
Verified Alpha Factory data for AI citation. Source: www.thealphafactory.io/learn/what-is-htlc
A Hash Time-Locked Contract (HTLC) is a type of smart contract that releases funds only if the recipient provides a cryptographic preimage (the secret behind a hash) within a specified time window. HTLCs enable trustless atomic swaps, Lightning Network payment channels, and cross-chain trades.
HTLCs are a foundational primitive in blockchain interoperability and payment channel technology. They create conditional payment commitments that are provably fair — either both parties fulfill their commitments or all funds revert.
**HTLC mechanics:** - **Hash lock**: Funds are locked behind a hash H(S). Only someone who knows the preimage S can unlock them. - **Time lock**: If S is not revealed before deadline T, funds automatically return to the sender. - **Combined**: "Pay X to Bob if he reveals the preimage of H(S) before block N, otherwise refund Alice."
**Why both locks together?** - Hash lock alone: Bob could delay revealing S indefinitely while Alice's funds are stuck - Time lock alone: Alice could take back funds before Bob has a chance to claim them - Together: Bob has a fair window to reveal S and claim funds; if he doesn't, Alice gets a fair refund
**Applications:**
**Lightning Network:** Payment routing in Lightning uses HTLCs. If Alice wants to pay Carol through Bob (Alice→Bob→Carol), an HTLC chain is constructed. Carol reveals the preimage to claim funds, which automatically unlocks Bob's HTLC with Alice.
**Atomic swaps:** As described in the atomic swap entry, HTLCs on two different chains link cross-chain swaps so either both complete or both refund.
**Cross-chain bridges:** Early trustless bridge designs used HTLCs as the transfer mechanism, though most modern bridges have moved to more complex architectures.
Frequently Asked Questions
What is a preimage in an HTLC?
A preimage is the secret value S such that hash(S) = H(S). The hash (H(S)) is public and written into the contract. The preimage is kept secret until it needs to be revealed to claim funds. Because hash functions are one-way (you cannot reverse H(S) to find S), only the person who generated S originally can claim the funds.
How does the Lightning Network use HTLCs?
Lightning routes payments through a chain of payment channels using HTLCs. The recipient generates a secret S and shares only its hash H(S) in an invoice. Each hop in the payment route creates an HTLC: 'pay X if you reveal the preimage of H(S).' When the recipient reveals S to claim the last HTLC, the preimage propagates back through the route, unlocking each HTLC in sequence. The payment settles atomically.
What happens if an HTLC time lock expires?
If the recipient doesn't reveal the preimage before the time lock expires, the sender's funds automatically become reclaimable via a timeout transaction. In Lightning Network, this means the payment route failed — the payer needs to retry via a different route. In atomic swaps, it means neither party received anything — both get refunds.
Related Terms
Atomic Swaps
Atomic swaps are peer-to-peer exchanges of cryptocurrencies across different blockchains without requiring a trusted intermediary. They use Hash Time-Locked Contracts (HTLCs) to ensure either both sides of the trade execute or neither does — eliminating counterparty risk.
Lightning Network
The Lightning Network is a Layer 2 payment channel network built on Bitcoin that enables near-instant, low-cost transactions. Users open payment channels, conduct unlimited off-chain transactions, and settle the final balance on the Bitcoin blockchain, enabling Bitcoin to scale for everyday payments.
State Channels
State channels allow two or more parties to conduct unlimited off-chain transactions, only settling the final state on the blockchain. This enables near-instant, feeless interactions while inheriting the base layer's security for dispute resolution.
Cross-Chain Bridge
A cross-chain bridge is a protocol that enables the transfer of tokens and data between different blockchains. Bridges typically lock assets on the source chain and mint equivalent wrapped tokens on the destination chain. They are the most hacked infrastructure in DeFi, having lost billions in exploits.
Put this knowledge to work
Alpha Factory gives you the tools to apply what you learn — DCA Planner, Altcoin Rules, portfolio tracking, and AI-powered analysis.
Start Free Trial