Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Glossary

Hash Time-Locked Contract (HTLC)

A Hash Time-Locked Contract (HTLC) is a type of smart contract that uses a cryptographic hash and a timelock to enable conditional, atomic payments, forming the basis for early trust-minimized swaps.
Chainscore © 2026
definition
BLOCKCHAIN PROTOCOL

What is a Hash Time-Locked Contract (HTLC)?

A foundational cryptographic primitive enabling conditional, time-bound payments across blockchain networks.

A Hash Time-Locked Contract (HTLC) is a type of smart contract that enables conditional payments by cryptographically locking funds with two release conditions: the presentation of a secret data preimage that matches a public hash, or the expiration of a predefined timelock. This mechanism creates a secure, trust-minimized escrow, allowing parties who do not trust each other to transact across payment channels or different blockchains. It is the core protocol enabling atomic swaps and the backbone of Lightning Network and other layer-2 scaling solutions.

The contract's operation hinges on two cryptographic primitives. First, a cryptographic hash function (like SHA-256) generates a public hash H from a secret preimage R. The payer locks funds in the HTLC, specifying that anyone who can reveal R (proving they know R such that hash(R) = H) can claim the payment. Second, a timelock (implemented via nLockTime in Bitcoin or block.number in Ethereum) sets a deadline. If the secret is not revealed before this deadline, the funds are refunded to the original payer, preventing funds from being locked indefinitely.

HTLCs are the essential building block for cross-chain atomic swaps, allowing for the peer-to-peer exchange of cryptocurrencies across different blockchains without centralized intermediaries. In this process, two parties create mirrored HTLCs on their respective chains. The revelation of the secret to claim funds on one chain automatically provides the necessary preimage to claim the funds on the other chain, making the swap all-or-nothing (atomic). This eliminates counterparty risk, as either the entire exchange completes successfully or all funds are returned.

Within payment channel networks like the Lightning Network, HTLCs facilitate multi-hop payments. A payment route is constructed where each intermediary node along the path creates an HTLC with the next node, each with a successively shorter timelock. The final recipient reveals the preimage to claim the payment, which then propagates backward through the chain of contracts, allowing each intermediary to claim their funds from the previous node. This design ensures the payment either completes fully along the route or fails entirely, with all intermediate HTLCs expiring and refunding.

While highly secure, HTLCs introduce specific risks and considerations. The most notable is hash-lock griefing, where a malicious participant can lock up a counterparty's capital by initiating an HTLC with a secret they never intend to reveal, forcing the victim to wait for the timelock expiry. Furthermore, careful coordination of timelock durations is critical in routing to avoid a scenario where an upstream timelock expires before a downstream one, potentially allowing an intermediary to steal funds. These constraints are addressed in more advanced protocols like PTLCs (Point Time-Locked Contracts).

etymology
TERM BACKGROUND

Etymology and Origin

The Hash Time-Locked Contract (HTLC) is a foundational smart contract primitive whose name and function are derived from its core cryptographic and temporal components.

The term Hash Time-Locked Contract is a descriptive compound noun. Hash refers to the cryptographic hash function, typically SHA-256, used to create a secret-proof payment condition. Time-Locked specifies the contract's built-in expiration mechanism, enforced by a relative cltv (CheckLockTimeVerify) or absolute csv (CheckSequenceVerify) timelock in Bitcoin, or a block number deadline in Ethereum. Contract denotes its nature as a self-executing agreement on a blockchain. The acronym HTLC emerged from technical documentation and developer discourse around 2015-2016 as the Lightning Network and cross-chain atomic swap protocols were being conceptualized.

The conceptual origin of HTLCs is deeply intertwined with the development of off-chain payment channels and atomic swaps. They are a direct implementation of a fair exchange protocol, solving the problem of trustless conditional payment without a central intermediary. The core idea can be traced to cryptographic concepts like hash puzzles and timed commitments. The first major practical implementation and popularization of HTLCs occurred within the Bitcoin Lightning Network whitepaper (2015) as the essential building block for multi-hop payments, enabling users to route payments across a network of bidirectional channels.

The evolution of HTLCs demonstrates their role as a protocol-level primitive. While the basic structure is simple—a conditional payment that can be claimed with a secret preimage or refunded after a timeout—its implications are profound. This design allows for complex, interconnected financial operations like cross-chain atomic swaps between different blockchains (e.g., Bitcoin for Litecoin) and atomic cross-chain transactions in interconnected ecosystems. The HTLC pattern has since been generalized and implemented on smart contract platforms like Ethereum, where it facilitates decentralized finance (DeFi) applications such as trustless bridging and conditional liquidity provisions.

key-features
HTLC MECHANICS

Key Features

A Hash Time-Locked Contract (HTLC) is a smart contract that enables conditional payments using a cryptographic hash and a timelock. It is a fundamental primitive for trustless, atomic swaps and payment channels.

01

Cryptographic Hash Preimage

The core conditional logic of an HTLC. A payment is locked with a cryptographic hash (e.g., SHA-256) of a secret value, known as the preimage. The funds can only be claimed by the recipient revealing this preimage, which proves they have the secret. This mechanism creates a proof-of-payment condition without requiring trust between parties.

02

Timelock Expiry

A safety mechanism that ensures funds are not locked indefinitely. The contract includes a timelock, typically implemented via OP_CHECKLOCKTIMEVERIFY (CLTV) or OP_CHECKSEQUENCEVERIFY (CSV). If the recipient fails to claim the payment by revealing the preimage before the timelock expires, the funds are refunded to the original sender. This creates a strict deadline for the conditional transaction.

03

Atomic Cross-Chain Swaps

HTLCs enable trustless exchange of assets across different blockchains without a centralized intermediary. The process is atomic: either the entire swap completes, or it fails and funds are refunded.

  • Step 1: Party A locks BTC in an HTLC on Bitcoin, using hash H.
  • Step 2: Party B, seeing the lock, locks ETH in an HTLC on Ethereum using the same hash H.
  • Step 3: Party A claims the ETH by revealing the preimage, which Party B then uses to claim the BTC.
04

Payment Channel Networks

HTLCs are the building block for multi-hop payments in Lightning Network and similar Layer 2 solutions. They allow a payment to be routed through a path of interconnected channels. Each hop in the path is secured by its own HTLC, creating a chain of conditional payments. The revelation of the preimage propagates backwards, ensuring all intermediaries get paid only if the final recipient does.

05

Interoperability Primitive

Beyond simple swaps, HTLCs are a versatile tool for cross-chain interoperability. They are used in:

  • Cross-chain bridges for asset transfers.
  • Decentralized exchanges (DEXs) facilitating trades between native assets.
  • Oracle-based conditional payments, where the preimage is revealed upon a real-world event. Their simplicity and cryptographic security make them a foundational protocol for decentralized finance (DeFi).
06

Security & Limitations

While secure, HTLCs have specific constraints and attack vectors.

  • Liquidity Lockup: Funds are immobilized for the duration of the timelock.
  • Griefing Attacks: A malicious party can start a swap to lock another's capital without intending to finish.
  • Timelock Mismatch: Careful coordination is required to ensure refund paths are safe across different blockchains with varying confirmation times.
  • Hash Collision Risk: The security relies on the cryptographic strength of the hash function.
how-it-works
CORE MECHANISM

How It Works: The Atomic Swap Mechanism

A Hash Time-Locked Contract (HTLC) is the cryptographic protocol that enables trustless, cross-chain asset exchanges without a centralized intermediary.

A Hash Time-Locked Contract (HTLC) is a specialized smart contract that enforces a conditional payment using a cryptographic hash and a time constraint. It is the foundational protocol enabling atomic swaps between different blockchain networks. The contract stipulates that the recipient must provide a cryptographic proof, known as a preimage, to unlock and claim funds before a specified time limit expires. If the proof is not provided in time, the funds are automatically refunded to the original sender. This creates a secure, trust-minimized environment for peer-to-peer exchange.

The atomic swap process using an HTLC involves two sequential, interlocking contracts. First, Party A initiates the swap by locking funds into an HTLC on Chain A, specifying a hash of a secret preimage and a refund timeout. Party B, upon verifying this lock, creates a corresponding HTLC on Chain B, locking their funds with the same hash value. To claim the funds on Chain A, Party B must reveal the preimage, which simultaneously reveals it to Party A, allowing them to claim the funds on Chain B. This sequence ensures the swap is atomic—it either completes entirely for both parties or fails entirely, with funds returned.

The security of an HTLC rests on two critical components: the hashlock and the timelock. The hashlock ensures that only the party possessing the correct preimage can claim the payment, making the transaction conditional on the secret's revelation. The timelock provides a safety mechanism, guaranteeing that locked funds are not held indefinitely; if the counterparty fails to act, the funds are recoverable after the timeout period. This design eliminates counterparty risk, as neither participant can steal funds or stall the transaction indefinitely.

HTLCs are not limited to simple asset swaps. They are the core building block for more complex Layer 2 and cross-chain functionalities. For example, they are essential to the operation of the Lightning Network for Bitcoin, where they facilitate instant, low-cost payments through a network of payment channels. In cross-chain bridges and decentralized finance (DeFi) protocols, HTLCs enable the secure movement of liquidity and the creation of synthetic assets across disparate blockchain ecosystems, though often wrapped within more complex contractual logic.

While revolutionary, HTLC-based atomic swaps have practical limitations. They require both participating blockchains to support the same cryptographic hash function (e.g., SHA-256) and programmable smart contract or scripting functionality, which initially limited swaps to chains like Bitcoin and Litecoin. The process can also be relatively slow and manual compared to centralized exchanges. Furthermore, the public nature of the hash on-chain makes the swap detectable, potentially reducing privacy. These constraints have spurred the development of more advanced cross-chain communication protocols.

visual-explainer
VISUAL EXPLAINER

Hash Time-Locked Contract (HTLC)

A technical deep dive into the smart contract mechanism that enables trustless cross-chain and off-chain transactions.

A Hash Time-Locked Contract (HTLC) is a type of smart contract that enforces a conditional payment, requiring the recipient to provide a cryptographic proof of payment (a secret preimage) within a specified time limit, or else the funds are returned to the sender. This creates a secure, trustless escrow for atomic swaps and payment channel networks. The core components are the hash lock, derived from a secret, and the time lock, a blockchain-enforced deadline.

The process begins when Party A initiates an HTLC, locking funds with a cryptographic hash of a secret known only to Party B. To claim the funds, Party B must publish the secret preimage that generates the matching hash, which is then recorded on-chain. This act of revealing the secret can be used to trigger a subsequent, linked HTLC in a different transaction or on another blockchain, enabling cross-chain atomic swaps without a trusted intermediary.

HTLCs are the foundational building block for Lightning Network and similar Layer 2 payment channels. They allow users to route payments across a network of bidirectional channels without requiring trust in intermediate nodes. Each hop in the payment route is secured by a separate HTLC, creating a chain of conditional payments that settles atomically. This enables near-instant, low-cost microtransactions that are ultimately secured by the underlying blockchain.

The security of an HTLC hinges on its two failure states. If the recipient fails to provide the secret before the cltv_expiry (CheckLockTimeVerify) deadline, the sender can reclaim the funds via a refund transaction. This time-lock mechanism protects the sender from funds being locked indefinitely. Conversely, the hash lock ensures only the intended recipient, who possesses the secret, can claim the payment, preventing theft during the routing process.

Beyond payment channels, HTLCs enable atomic swaps, allowing for the direct, peer-to-peer exchange of cryptocurrencies across different blockchains (e.g., Bitcoin for Litecoin). They are also used in more complex cross-chain communication protocols and decentralized finance (DeFi) applications for interoperability. The elegance of HTLCs lies in their use of simple, native blockchain opcodes like HASH160 and CHECKLOCKTIMEVERIFY to create powerful, trust-minimized financial primitives.

examples
HASH TIME-LOCKED CONTRACT (HTLC)

Protocol Examples & Use Cases

HTLCs are cryptographic smart contracts that enable conditional, trust-minimized value transfer across blockchains or payment channels, forming the backbone of atomic swaps and the Lightning Network.

05

Conditional Escrow & Payments

Beyond crypto, HTLC logic applies to conditional escrow services and oracle-dependent payments. The contract releases funds only upon provable fulfillment of off-chain conditions:

  • Example: An insurance payout that requires proof of a verifiable event (e.g., flight delay data from an oracle).
  • The payout is locked in an HTLC with the condition being the submission of a valid data signature.
  • The time-lock ensures the insurer gets a refund if the claim is not filed within a deadline. This creates cryptographically-enforced agreements without traditional legal overhead.
06

Key Mechanism: Hash & Time-Lock

The security of an HTLC rests on two core cryptographic primitives:

  • Cryptographic Hash (H): A one-way function (e.g., SHA-256). The payer creates a secret preimage (R), publishes its hash H(R), and the contract only executes if R is revealed.
  • Absolute Time-Lock (CLTV): A CheckLockTimeVerify clause that makes funds spendable only after a specific block height or timestamp.
  • Relative Time-Lock (CSV): A CheckSequenceVerify clause that starts a countdown after a previous transaction is confirmed. Together, these enforce the "claim or refund" logic that prevents funds from being locked indefinitely.
security-considerations
HASH TIME-LOCKED CONTRACT (HTLC)

Security Considerations & Limitations

While HTLCs are a fundamental primitive for trust-minimized swaps, their security model introduces specific operational risks and constraints that must be understood.

01

Preimage Secrecy & Hash Strength

The security of an HTLC hinges on the cryptographic secrecy of the preimage (the secret key). If the hash function (e.g., SHA-256) is compromised or the preimage is leaked before the contract is funded, the locked funds can be stolen. The hash function must be collision-resistant to prevent an attacker from finding a second valid preimage to claim the funds.

02

Timelock Expiry Risks

The timelock is a critical parameter that creates two primary risks:

  • Refund Deadlock: If the timelock on the refund path is set too short on the initiating chain, a participant could claim the refund before the counterparty has had time to claim the asset on the destination chain.
  • Capital Inefficiency: Funds are locked and unusable for the entire duration of the timelock, which can be hours or days for slower blockchains, exposing participants to opportunity cost and price volatility.
03

Liveness Requirement & Griefing

HTLCs require both parties to be online and monitoring the blockchain to submit transactions within the timelock windows. This creates a liveness assumption. A malicious participant can initiate a swap and then go offline, forcing the honest party to wait for the timelock to expire to reclaim funds—a form of griefing attack that wastes time and transaction fees without direct financial theft.

04

Routing & Intermediate Node Risk

In multi-hop payment channels (like the Lightning Network), HTLCs are chained. This introduces intermediate node risk. A node in the path could fail to forward a preimage, causing the entire route to fail. While funds are eventually refundable, this disrupts service. More critically, a malicious intermediate node could theoretically attempt wormhole attacks or fee sniping to profit from timing discrepancies.

05

Blockchain Congestion & Fee Uncertainty

The ability to claim funds or execute a refund is contingent on getting a transaction confirmed on-chain before the timelock expires. During periods of high network congestion, transaction fees may spike unpredictably. A participant may be unable to pay a sufficient fee in time, resulting in a loss of funds. This makes HTLCs unsuitable for environments with highly variable block times or fee markets.

06

Lack of Atomicity Across Heterogeneous Chains

A cross-chain HTLC is not atomic in the strict cryptographic sense; it is probabilistically atomic based on timelocks. If the two involved blockchains have vastly different block times or finality characteristics (e.g., Bitcoin vs. a fast Proof-of-Stake chain), it becomes extremely difficult to set safe, efficient timelocks. This complexity is a primary reason HTLCs are often superseded by more advanced protocols like Atomic Swaps with adaptor signatures.

CROSS-CHAIN TRANSFER MECHANISMS

HTLC vs. Modern Bridge Models

A comparison of the foundational atomic swap mechanism with contemporary, custodial and trust-minimized bridge architectures.

Feature / MechanismHash Time-Locked Contract (HTLC)Custodial BridgeTrust-Minimized Bridge

Core Trust Model

Trustless (Cryptographic)

Centralized Custodian

Decentralized Validator Set

Liquidity Source

Peer-to-peer

Centralized Vault

Liquidity Pools / Mint-Burn

Transfer Speed

Minutes to hours

< 5 minutes

1-10 minutes

Supported Assets

Identical assets on both chains

Any whitelisted asset

Wrapped representations

Capital Efficiency

Low (requires locked capital per swap)

High (shared liquidity pool)

Variable (pool-based)

Security Guarantees

Atomicity (all-or-nothing)

Custodial risk

Economic security (slashing, fraud proofs)

Complexity & Cost

High on-chain gas

Low user cost, high op-ex

Moderate (relayer fees, gas)

Use Case Primarily

Atomic swaps, direct P2P

Centralized exchanges, retail

DeFi interoperability

evolution
HISTORICAL CONTEXT

Evolution and Current State

The Hash Time-Locked Contract (HTLC) emerged as a foundational cryptographic primitive that enabled the development of decentralized, trust-minimized financial applications, most notably the Lightning Network.

A Hash Time-Locked Contract (HTLC) is a type of smart contract that enables conditional payments across a network of payment channels by using a cryptographic hash and a timelock. It functions as the core mechanism for atomic swaps and off-chain scaling solutions. The contract locks funds with two possible unlock conditions: the recipient must present the cryptographic preimage (the secret data that produces a specific hash) before a deadline, or the funds are returned to the sender after the timelock expires. This creates a secure, self-enforcing escrow without a trusted third party.

The concept was formally introduced in the Lightning Network whitepaper by Joseph Poon and Thaddeus Dryja in 2016 as the essential building block for bidirectional payment channels. Its design solved the critical problem of secure, multi-hop routing in a decentralized network. By chaining HTLCs together, a payment can be routed across multiple intermediaries, with each step contingent on the revelation of the same secret. This ensures the entire transaction either completes atomically or fails entirely, preventing loss of funds if any participant becomes uncooperative.

The evolution of HTLCs has been marked by refinements to address practical challenges. Early implementations faced issues with hash collision security and the complexity of managing numerous concurrent timelocks. Later advancements, such as Point Time-Locked Contracts (PTLCs), which use cryptographic signatures instead of hash preimages, offer improved privacy and efficiency. Today, HTLCs remain a vital, though sometimes legacy, component in cross-chain bridges and decentralized finance (DeFi) protocols, demonstrating their enduring utility as a trust-minimization tool in blockchain interoperability.

HASH TIME-LOCKED CONTRACT (HTLC)

Frequently Asked Questions (FAQ)

A Hash Time-Locked Contract (HTLC) is a smart contract that enables conditional payments across blockchains or payment channels, requiring the recipient to provide proof of payment within a set timeframe. These questions cover its core mechanics, applications, and security considerations.

A Hash Time-Locked Contract (HTLC) is a type of smart contract that facilitates trustless, conditional payments by requiring the recipient to cryptographically prove they have the payment within a specific time window. It works using two key components: a cryptographic hash and a timelock. The sender creates a payment locked with a hash of a secret. The recipient can only claim the funds by submitting the correct preimage (the original data that produces the hash) before the timelock expires. If they fail, the funds are automatically refunded to the sender. This mechanism is the foundation for atomic swaps and cross-chain transactions.

ENQUIRY

Get In Touch
today.

Our experts will offer a free quote and a 30min call to discuss your project.

NDA Protected
24h Response
Directly to Engineering Team
10+
Protocols Shipped
$20M+
TVL Overall
NDA Protected Directly to Engineering Team