What Is Hashlock?
Also known as: Hash Lock, HTLC, Hashed Timelock Contract
In short
A hashlock is a spending condition under which funds can be spent only by revealing the secret data that produces a predetermined hash value; combined with a timelock, it forms the basis of the Lightning Network and atomic swaps.
In a hashlock, the party setting up the transaction generates a random secret value (the preimage) and shares only the hash of this value. The funds are locked so that they can be spent by the person who presents the data whose hash matches this one. Because hash functions are one-way, finding the secret value from the hash is practically impossible; when the secret value is revealed, however, anyone can easily check its correctness.
Although a hashlock is often mentioned together with a timelock, the two are separate mechanisms. A timelock ensures that funds cannot be spent before a certain time or block height. When the two are combined, a hashed timelock contract (HTLC) emerges: if the recipient reveals the secret value within the set time, they receive the funds; if the time expires, the funds return to the sender.
For example, two people performing an atomic swap between two different blockchains set up HTLCs tied to the same hash. When one of the parties reveals the secret value to claim the funds on their side, the other party can use the same value to claim the funds on the counterpart chain; thus the swap either takes place completely or not at all. The secure routing of payments across multiple channels on the Lightning Network is based on the same principle.
Last updated: · This content is for information purposes only and is not investment advice.

