A Hashed Timelock Contract (HTLC) is a type of smart contract, self-executing code that lives on a blockchain, that lets two people exchange assets directly with each other, without needing a middleman. It works through two prebuilt conditions. In essence, a secret code must be revealed to be able to claim the funds. If the swap isn’t completed in time, an automatic refund occurs. Both parties end up getting what they agreed to, or otherwise, neither loses anything at all.
Think of it like a secure drop-box swap. You place your package in one box and lock it with a combination. Your trading partner places their package in another box and locks it with the same combination. Neither of you can open your box until the combination is shared, and if either of you fails to show up before the clock runs out, both boxes pop open and return whatever was placed inside. The trade completes fully or cancels entirely. There is no halfway.
The two mechanisms that make this work each have a name. It works through two prebuilt conditions. In essence, a secret code must be revealed to be able to claim the funds. If the swap isn’t completed in time, an automatic refund occurs. Both parties end up getting what they agreed to, or otherwise, neither loses anything at all. Together, they make the contract self-enforcing, no judge, no bank, no arbitrator required.
You have probably benefited from HTLCs without realizing it. They are the backbone of the Bitcoin Lightning Network, a payment system built on top of Bitcoin that enables fast, low-fee transactions. HTLCs in Lightning payments work to ensure that the payment will return to the sender if one of the payment’s hops fails whether they are either routed through a payment channel that isn’t valid or has exceeded its expiry. A type of escrow called HTLCs makes it possible for two parties to agree to a marriage. Using an HTLC on each chain, for example, a Bitcoin holder and a Litecoin holder can swap directly. The Lightning Network’s Rusty Russell and others are believed to have come up with it in 2015.
For anyone trying to understand how crypto payments scale without sacrificing security, HTLCs are a foundational piece. They prove that two strangers can transact across different blockchains, without trusting each other, and without trusting anyone else.