Alpha Factory
Blockchain

HTLC (Hash Time-Locked Contract)

Menno van Ravels - Alpha Factory

By - 13 years in crypto, 3 bear markets survived, zero paid promotions

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

Speakable: TrueEntity: Verified

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.

Free account · no card

Save your coins, get price alerts and plan your exits

  • Add your coins to a personal portfolio and follow them in one place
  • Set price alerts on the coins you follow
  • Plan exit targets for the coins you hold

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.

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.

Unlock Premium