If you’ve done any research on the lightning network you’ve probably heard about Hash Time Locked Contracts (HTLCs):

What exactly are they?
Why do we need them?
How do they enable trustless payments?

I’ve been working with lightning for years, let me break it down for you 👇
Hash Time Locked Contracts are a way of doing conditional payments using smart contracts on Bitcoin.

As the name implies they use both a hashlock and a timelock to enable this functionality.

So what exactly are hashlocks and timelocks?
A hash refers to the output of a hash function like SHA256.

The important property to understand is that the hash provides no info about the input used to generate it.

A hashlock is a payment that is conditional on the recipient knowing the input that generates the hash
A time lock comes in a few forms in Bitcoin but generally it is a condition placed on an UTXO so that it cannot be spent by the recipient until a certain time or block height.

It means Alice can send Bob some money that he cannot spend until some specified time.
We can use these constructs to enable trustless routing of payments over the lightning network.

Let’s imagine a scenario where Alice has a channel with Bob and Bob has a channel with Carol.

Alice wants to pay Carol but doesn’t want to open a channel. How do HTLCs help?
Carol can generate a random number called the payment secret and use a hash function to get a hash we’ll call the payment hash.

She gives the payment hash to Alice.

Alice tells Bob that she wants to route a payment to Carol and that I know you have a channel open with her.
Let’s say Alice wants to pay Carol 10K sats.

Alice uses a hash lock to pay Bob 11K sats that he can only receive if he has the secret used to generate the hash Alice got from Carol.

Bob wants to earn the 1K sats fee and knows he can get the secret from Carol.
Bob then does the same thing with Carol.

He uses a hash lock to pay Carol the 10K sats knowing she can only claim the payment if she provides the payment secret.

He’s okay doing this because if he gets the secret he can use it to claim 11K sats from Alice.
Carol wants the 10K sats so she gives the secret to Bob and claims her 10K sats.

Bob uses the secret to claim the 11K sats from Alice. Alice has paid Carol 10K sats and Bob earned 1K sats for routing the payment for Alice.

This is how trustless lightning payments work.
Wait but what about the time lock?

The time lock is used so that participants can get their sats back if anyone disappears.

So Alice’s payment to Bob really has two conditions:

1) Pay Bob 11K sats if he has the secret.
2) Pay Alice 11K sats after some timeout.
This means if Bob bails or can’t get the secret for some reason then Alice’s funds are not lost.

She will be able to get them back after the time lock expires.

It also means Bob has a limited amount of time to get the secret from Carol.
I hope this helped you understand Hash Time Locked Contracts (HTLCs) and why they are fundamental building blocks to the lightning network.

Please follow if you want to learn more about Bitcoin every day.

• • •

Missing some Tweet in this thread? You can try to force a refresh

Keep Current with John Cantrell

John Cantrell Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!


Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @JohnCantrell97

Jan 17,
A lot of people think that Bitcoin is “too expensive” for them to get involved. That it’s a tool for the already wealthy. This is not true. You might be wondering:

Do I need to buy a whole coin?
How should I value Bitcoin?

Let me explain a bit about how I think about it 👇
First and foremost, no, you do not need to buy a whole coin.

A Bitcoin is divisible into 100M units called Satoshis (yes, after Satoshi Nakamoto, the pseudonymous creator of Bitcoin).

You can buy ANY amount you’re comfortable with. As little as $0.25 on the @ln_strike app!
There are a million ways people try to value Bitcoin and all of them will give you different results.

I try to stay away from short term price predictions and look at it as more than an investment.

Bitcoin provides a new form of digital money that is native to the internet.
Read 8 tweets
Jan 15,
Bitcoin is designed to emit a total of 21,000,000 coins with the last bits of coin to be mined in the year 2140.

What exactly is the supply schedule?
What happens after 2140?

The supply schedule is one of the most important aspects of Bitcoin, let me break it down for you 👇
Every block that is mined is allowed to produce a certain amount of bitcoin.

This amount is called the block reward and it started at 50 bitcoin per block.

Every 210,000 blocks (roughly every 4 years) this reward halves. From 50 to 25 to 12.5 to 6.25 and so on.
This is what is referred to as the supply schedule.

The exact parameters aren’t important, it’s the fact that it is known ahead of time and cannot change that makes Bitcoin so revolutionary.

Everyone can know exactly how much BTC will exist at any point in the future.
Read 9 tweets
Jan 14,
What an exciting week it’s been in Bitcoin. Is it ever boring? Definitely not.

I hope you learned a lot from my educational threads this week.

In no particular order, here’s what I found most important or interesting this week 👇
@adamcurry explains to @joerogan why he believes his money is safer in Bitcoin, why it will be a huge part of our future, and why to stay away from shitcoins.

A must listen.

Read 9 tweets
Jan 14,
If you’ve done any research into Bitcoin you’ve heard people talk about private key storage.

What are keys?
What’s the difference between hot and cold storage?
Which should I use?

Keys are one of the most important topics in Bitcoin. Let me break it down for you 👇
To understand keys you need to know a little bit about cryptography.

Keys generally come as a pair of public and private keys.

The most common use of keys is to encrypt and decrypt messages.

However, in Bitcoin they are primarily used to generate and verify signatures.
In order to spend Bitcoin you need to produce a signature by signing every tx you make in order to prove to the network that you control the UTXOs being spent.

You use your private keys to produce this signature.

If you need a refresher on UTXOs:
Read 11 tweets
Jan 13,
You probably saw the news this week that two people have solo mined a Bitcoin block and earned 6.25 BTC worth over $250,000. You’re probably wondering

What is solo mining?
How much does it cost?
What are the odds?
Should you be mining?

Let me break it down for you 👇
Solo mining is exactly what it sounds like. It’s what you probably think of when you think of mining. It means someone is mining all by themselves.

So why is it explicitly called out as “solo mining”? It’s because the norm these days is to mine as part of a pool.
What is a mining pool? Well as more and more people mine it becomes harder and harder to mine a block by yourself.

This means the time it takes for you to find a block is also increasing. In order to generate a steady stream of revenue miners often pool together.
Read 16 tweets
Jan 12,
We learned yesterday that when you own Bitcoin, you control keys that can spend UTXOs. In case you missed it:

Let me explain how with proper UTXO management you can save money and maintain your privacy 👇
How can learning to manage your UTXOs help you save money?

Well if you remember from this thread:

We learned that the cost to send Bitcoin is proportional to the size of the tx and that the size of the tx depends on the size of the inputs and outputs.
The UTXOs we control are used as inputs for all txs that we make. This gives us control over the size of our tx.

When picking inputs to use we need to make sure the total amount in is >= the total amount going out. We can save money by minimizing the number of inputs we use.
Read 15 tweets

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!


0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy


3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!