DEV Community

Oghenovo Usiwoma
Oghenovo Usiwoma

Posted on

HODL Invoices vs BOLT11 Invoices; A comparison

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. 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. 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 or settle it by releasing the preimage for the 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

Top comments (0)