A Hashed TimeLock Contract (HTLC) is a type of smart contract used in blockchain systems to control payments with clear conditions. It makes sure that a transaction only goes through if specific rules are met within a fixed time. If those rules are not met, the funds go back to the original owner.
HTLCs are widely used in atomic swaps and payment channels because they reduce the need for trust between parties. Instead of relying on intermediaries, both sides rely on math, cryptography, and preset deadlines.
An HTLC combines two main ideas: a hashlock and a timelock. Together, they control when and how funds can be spent.
The sender locks funds in a contract. The receiver can claim those funds only by revealing a secret value. This value must match a previously shared cryptographic hash. If the receiver does not reveal the correct value before the deadline, the contract expires, and the funds return to the sender.
This setup allows two people to safely exchange assets without knowing or trusting each other.
A hashlock is based on cryptographic hashing. One party creates a secret value and turns it into a hash using a hash function. Only the hash is shared publicly.
To unlock the funds, the other party must provide the original secret. The contract checks the hash of that secret. If it matches the stored hash, the condition is satisfied, and the funds are released.
Because hash functions are one-way, it is not possible to guess the secret from the hash alone.
A time lock adds a time limit to the contract. It defines how long the funds will stay locked while waiting for the correct secret.
If the receiver does not act before the deadline, the contract automatically allows the sender to reclaim the funds. This prevents assets from being locked forever and protects both sides from losing access to their money.
HTLCs are a core building block of atomic swaps. An atomic swap lets two users exchange cryptocurrencies from different blockchains directly.
The same secret is used across both blockchains. When one party reveals the secret to claim funds on one chain, the other party can use that same secret to claim funds on the other chain. The timelock ensures that if something goes wrong, both parties can safely recover their assets.
HTLCs are also used in off-chain payment networks like the Lightning Network. In this case, they help route payments across multiple participants.
Each step in the route uses an HTLC. The payment only completes if the secret is revealed within the allowed time. This design allows fast, low-cost payments while keeping the system secure.
HTLCs reduce counterparty risk by removing the need for trust. Funds are controlled by code rather than by people. The rules are enforced automatically by the blockchain.
At the same time, HTLCs depend on correct timing and proper setup. If deadlines are too short or secrets are mishandled, users may face failed transactions or locked funds.
HTLCs can be complex to implement and understand, especially for new users. They also rely on compatible scripting or smart contract features across blockchains. Not all networks support the same hashing or timelock mechanisms.
In some cases, network congestion can cause delays that interfere with timelocks, leading to canceled transactions.