
Hashed Timelock Contract (HTLC)
A Hashed Timelock Contract (HTLC) is a type of smart contract used in blockchain applications to eliminate counterparty risk by enabling the implementation of time-bound transactions. A typical HTLC transaction between them takes place as follows: 1. Alice generates a hash from her private key and sends it to Bob on Litecoin blockchain. A Hashed Timelock Contract (HTLC) is a type of smart contract used in blockchain applications to eliminate counterparty risk by enabling the implementation of time-bound transactions. 3. Once Alice receives Bob’s Litecoin transaction, she signs it using the original key that is already available with her in the pre-image. A hashed timelock contract (HTLC) reduces counterparty risk in decentralized smart contracts by effectively creating a time-based escrow.

What Is a Hashed Timelock Contract (HTLC)?
A Hashed Timelock Contract (HTLC) is a type of smart contract used in blockchain applications to eliminate counterparty risk by enabling the implementation of time-bound transactions. In practical terms, this means that recipients of a transaction have to acknowledge payment by generating cryptographic proof within a certain timeframe. Otherwise, the transaction does not take place.
Atomic swaps, cross-chain trading between cryptocurrencies is often achieved using HTLCs. In addition, Bitcoin’s lightning network (LN) also employs HTLCs.



How a Hashed Timelock Contract Works
A Hashed Timelock Contract (HTLC) uses several elements from existing cryptocurrency transactions. For example, HTLC transactions use multiple signatures, which consist of a private-public key, to verify and validate transactions. But there are two elements that distinguish HTLC from standard cryptocurrency transactions or ordinary smart contracts.
The first element is the hashlock. A hashlock is a hashed, or cryptographically scrambled version of a public key generated by the originator of a transaction. The associated private key is then used to unlock the original hash. In HTLC, the originating party generates a key and hashes it. The hash is stored in a pre-image that is subsequently revealed during the final transaction. HTLCs are programmed to expire after a certain period of time or number of blocks generated, creating a known termination date.
The second important element of HTLC is a timelock. Two different timelocks are used to set time constraints on contracts generated using HTLC. The first one is CheckLockTimeVerify (CLTV). It uses a time base to lock and release bitcoins. This means that time constraints are hardcoded and coins are released only at a specific time and date or a specific height of block size.
The second one is CheckSequenceVerify (CSV). It is not dependent on time. Instead, it uses the number of blocks generated as a measure to keep track of when to finalize a transaction.
To conduct a transaction using HTLC, interested parties need to open channels with each other.
Real-World Examples of a Hashed Timelock
Suppose Alice wants to exchange her Bitcoin for Litecoin from Bob. A typical HTLC transaction between them takes place as follows:
- Alice generates a hash from her private key and sends it to Bob on Litecoin blockchain. She also generates a pre-image of the hash by creating a nominal transaction. This pre-image will help her validate and finalize the transaction.
- Bob also generates a hash from his key and sends it to Alice. In addition to this, he creates a pre-image by conducting a nominal transaction (in Litecoin) with Alice.
- Once Alice receives Bob’s Litecoin transaction, she signs it using the original key that is already available with her in the pre-image. Bob does likewise on his end, using his private key to unlock Alice’s transaction.
Related terms:
Atomic Swaps Defined
Atomic swaps are smart contracts that enable exchanges from one cryptocurrency to another without using centralized intermediaries. read more
Block (Bitcoin Block)
Blocks are files where data pertaining to the Bitcoin network are permanently recorded, and once written, cannot be altered or removed. read more
Blockchain : What You Need to Know
A guide to help you understand what blockchain is and how it can be used by industries. You've probably encountered a definition like this: “blockchain is a distributed, decentralized, public ledger." But blockchain is easier to understand than it sounds. read more
Cryptocurrency : What Is Cryptocurrency?
A cryptocurrency is a digital or virtual currency that uses cryptography and is difficult to counterfeit because of this security feature. read more
Ether (ETH)
Ether is the cryptocurrency of the Ethereum network. All of the programs linked with the Ethereum network require computing power; Ether is the token that is used to pay for this power. read more
Hash
A hash is a function that converts an input of letters and numbers into an encrypted output of a fixed length. read more
Lightning Network
Lightning Network is a second layer to bitcoin's blockchain that proposes to decongest its network by creating micropayment channels between two parties. read more
Private Key
A private key is a sophisticated form of cryptography that allows a user to access their cryptocurrency. read more
Proof of Burn (Cryptocurrency)
The proof of burn (POB) consensus algorithm combines the proof of work (POW) and proof of stake (POS) and partially overcomes their shortcomings. read more
Proof of Work (PoW)
Proof of work describes the process that allows the bitcoin network to remain robust by making the process of mining, or recording transactions, difficult. read more