HODL Invoices vs BOLT11 Invoices; A comparison
Tags: bitcoin, lightning
Published: 2023-03-02 07:16:17

Lightning is a second layer for Bitcoin that uses micropayment channels to scale the blockchain’s capability to conduct transactions more efficiently. This layer consists of multiple nodes that can open and close payment channels with each other, without having to broadcast every transaction to the Bitcoin network. This way, Lightning can enable faster and cheaper transactions, while still maintaining the security and decentralization of Bitcoin.

A Lightning invoice is a request for payment that contains the amount, destination, expiry time, and a cryptographic signature of the recipient. A payer can scan or copy a Lightning invoice and use it to initiate a payment through their Lightning wallet. A Lightning invoice can also include additional information such as a description or an image.

A Lightning HODL invoice is a special type of Lightning invoice that allows the recipient to delay the settlement of the payment until they reveal a preimage (a secret piece of data) that matches a hash (a unique fingerprint) embedded in the invoice. This feature can be useful for scenarios where the recipient wants to provide some service or proof before accepting the payment, such as delivering goods, verifying identity, or completing a task.

## How to create a Bolt11 invoice with LND's API
See [lnd's add-invoice API](https://lightning.engineering/api-docs/api/lnd/lightning/add-invoice). You will need to specify:
- The amount you want to receive in satoshis
- The expiry time in milliseconds
- The description (optional)
- The preimage (optional, LND will generate one for you)
Your invoice will be valid only for the expiry time you set. After it expires, it cannot be paid anymore. It can also be paid only once.

## How to create a lightning HODL invoice with LND's API
See [lnd's add-hodl-invoice API](https://lightning.engineering/api-docs/api/lnd/invoices/add-hold-invoice). A HODL invoice is very similar to a Bolt11 invoice but because the preimage is not released immediately on payment, you can [cancel the invoice](https://lightning.engineering/api-docs/api/lnd/invoices/cancel-invoice) or [settle it by releasing the preimage for the invoice](https://lightning.engineering/api-docs/api/lnd/invoices/settle-invoice).

**Even if you don't release the preimage in a Bolt11 invoice, the invoice will not be canceled. The payer can keep trying to pay until the invoice expires or fails with incorrect_or_unknown_payment_details. LND also requires the preimage to generate a BOLT11 invoice, so you have no control over when it is revealed.**

## Conclusion
HODL invoices are good for situations where you want to receive payments only after fulfilling some condition or providing some service. For example,

- You can use them for escrow services where you hold funds until both parties agree on releasing them
- You can use them for atomic swaps where you exchange one cryptocurrency for another without trusting intermediaries
- You can use them for pay-per-view content where you charge users only after they watch your video or read your article
- You can use them for crowdfunding campaigns where you collect funds only after reaching your goal

HODL invoices are also good for enhancing privacy and security on the Lightning Network. By delaying payments until they are needed, you reduce the risk of losing funds due to channel closures, hacks, or thefts. You also reduce the amount of information that is exposed on the network, such as balances, fees, or routes.

HODL invoices are one of many innovations that make the Lightning Network more powerful and versatile. They demonstrate how Bitcoin’s native smart-contract scripting language can enable new possibilities for peer-to-peer transactions.

## References
- https://www.investopedia.com/terms/l/lightning-network.asp
- https://lightning.network/
- https://en.wikipedia.org/wiki/Lightning_Network
- https://medium.com/suredbits/lightning-101-what-is-a-lightning-invoice-d527db1a77e6
- https://lightningwiki.net/index.php/HODL_Invoice