DEV Community

Cover image for Streamlining Bitcoin Transactions with Lightning KeySend: The Future of Payments
Chinonso Amadi
Chinonso Amadi

Posted on

Streamlining Bitcoin Transactions with Lightning KeySend: The Future of Payments

The Lightning Network is one of the most exciting current developments in Bitcoin. With Lightning users to send or receive Bitcoin quickly and cheaply by moving transactions off the main bitcoin blockchain and with the use of lightning invoices.

However the introduction of invoices introduced a lot of complexities required when trying to make payments. One of them has to do with the lack of reuse of invoices and the payer not knowing the expiration of the invoice. Another is if the receiver needs to accept reoccurring payments with varying amounts, he/she would need to generate invoices with varying amount every time such payments are required. To address this complexity, The Lightning Keysend feature was introduced.

In this article, we will explore what Lightning KeySend is, how it works, and provide code examples using lncli to help you implement it in your own applications.

What is the Lightning Keysend?

Lightning KeySend is a new feature that allows a sender to send a Bitcoin transaction directly to the recipient’s public key, without the need for a traditional payment invoice. This eliminates the need for a recipient to generate and broadcast an invoice, reducing the time and fees associated with a typical transaction. KeySend transactions also offer a higher level of privacy compared to traditional invoices, as they do not require a recipient to share their public key with the sender.

Why did we need Keysend in Lightning?

Lightning KeySend was introduced to address several pain points in the traditional payment process on the Lightning Network. The main reasons for the introduction of KeySend are:

  • Speed: KeySend transactions eliminate the need for the recipient to generate and broadcast a payment invoice, reducing the time required to complete a transaction.

  • Cost: Traditional invoices require the recipient to broadcast a payment request, which incurs a fee on the network. KeySend transactions eliminate this fee, reducing the overall cost of a transaction.

  • Privacy: KeySend transactions do not require the recipient to share their public key with the sender, improving privacy for both parties.

  • User Experience: KeySend transactions provide a simpler and more intuitive user experience compared to traditional invoices, as they eliminate the need for the recipient to generate and broadcast a payment request.

How does Lightning KeySend work?

Lightning KeySend transactions work by using the recipient’s public key to generate a unique hash that serves as the payment identifier. The sender then sends a transaction to this hash, which the recipient’s Lightning node is able to claim. The recipient’s node uses their private key to verify that the payment was intended for them and then forwards it to the recipient’s wallet.

Send Payments Using KeySend

Keysend allows users in the Lightning network to send payments to others, directly to their public key, as long as their node has public channels and has keysend enabled. Keysend does not require the payee to issue an invoice.

To make sure you are able to receive payments via Keysend, add the following lines to your lnd.conf file:

[Application Options]

accept-keysend=1

...
Enter fullscreen mode Exit fullscreen mode

Then restart your node with lncli stop and lnd.

To send a payment, you can use the command:

lncli sendpayment --dest <destination public key> --amt <amount> --keysend
Enter fullscreen mode Exit fullscreen mode

You can include messages into your payments with the –data flag. This messages could additional information about your payment or something you would like the receiver to know. However the message string must be an encoded hex value, an exmaple would something written like this:

lncli sendpayment --dest 03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6 --amt 10 --data 7061796D656E7420666F72206120637570206F6620636F66666565 --keysend
Enter fullscreen mode Exit fullscreen mode

where my 7061796D656E7420666F72206120637570206F6620636F66666565 code when decoded translates to the word "payment for a cup of coffee"

Note: The above code is just a sample and may need modifications based on the specific implementation of lncli.

Conclusion

The main motivation behind KeySend was to improve the speed, cost, privacy, and user experience of payments on the Lightning Network. By introducing KeySend, the Lightning Network can offer a faster, cheaper, and more private alternative to traditional payment methods.

References

Top comments (0)