Lightning Network

Last updated 3 months ago

After deploying BTCPay Server, you may want to experiment with an innovative second-layer payment system built on top of Bitcoin protocol - the Lightning Network.

This guide will show you how to set up your Lightning Network node in BTCPay and guide you through the basics.

Before you proceed, please understand that Lightning Network is still in the experimental stage. Do not put the money you can't afford to lose. There is a high risk of you losing the money.

Take time to familiarize yourself with the risk. There's no backup for LND or c-lightning keys in BTCPay. Your keys are in a hot-wallet. This means :

  1. If you erase your BTCPay Server or your machine crashes - you lose all the funds.

  2. If your server gets hacked - a hacker can take all of your funds by accessing your keys.

While the keys from your Lightning Network don't have a backup and someone can steal them theoretically, your on-chain Bitcoin funds are safe and are never uploaded on the server.

As the technology matures and develops, things like a proper backup will be easier to implement in BTCPay.

BTCPay currently offers two implementations of the Lightning Network:

Choosing the Lightning Network implementation

On the installation, you'll have the option to choose the implementation. For web-interface installations, you can simply select the implementation from the drop-down menu. For docker you need to :

sudo su -
cd btcpayserver-docker
export BTCPAYGEN_LIGHTNING="implementationgoeshere"
. ./btcpay-setup.sh -i

For c-lightning use export BTCPAYGEN_LIGHTNING="clightning" For LND use export BTCPAYGEN_LIGHTNING="lnd"

To begin using Lightning, your blockchain needs to be fully synced.

Connecting your internal Lightning Node in BTCPay

Regardless of the implementation (c-lightning or LND) you've decided to use, the process of connecting your internal Lightning Node in BTCPay Server is the same.

  1. If you do not have a store, create one.

  2. Store Settings > General Settings > Lightning Network Experimental (located at the bottom of the page, scroll)

  3. Under Crypto tab, select cryptocurrency > Modify.

  4. At the next page, at the bottom under "connection string", click on the "click here" link. Your node information will be automatically added.

  5. Enable. Submit.

  6. Test Connection.

Your blockchain needs to be fully synced before you try to connect your Lightning Node, otherwise the connection will fail.

LightningNetworkSettup1
LightningNetworkSettup2
LightningNetworkSettup3
LightningNetworkSettup4

Getting Started with BTCPay and LND

The easiest way to use LND implementation with BTCPay is to use Zap wallet integration.

LNDBTCPay

LND Commands lncli

You can use lncli commands like described in their API docs but instead of using lncli you use the shell script in of the btcpayserver-docker repository calles bitcoin-lncli.sh.

If you're on Docker make sure you're in docker directory.

sudo su -
cd btcpayserver-docker
./bitcoin-lncli.sh

So instead of running lncli getinfo you would run ./bitcoin-lncli.sh getinfo

Run ./bitcoin-lncli.sh --help to see a full list of commands or check above mentioned API docs.

Getting Started with BTCPay and c-lightning

The most straightforward way to start using the c-lightning implementation in BTCPay is to use Spark Wallet integration. Just like Zap for LND, Spark is a graphical interface of your internal c-lightning node.

You can use Spark as an internal or external wallet. Internal wallet allows users to use Spark via the web-browser inside their BTCPay Server. You can also connect externally to a Spark mobile or desktop app just by scanning a QR code.

c-lightningbtcpay

Go to Server Settings > Services > Spark Server > See information

Accessing Spark wallet
Accessing Spark wallet

c-lightning Commands lightning-cli

To use clightning CLI it is the same like above for lncli but instead you use the shell script bitcoin-lightning-cli.sh

If you're on Docker make sure you're in docker directory.

sudo su -
cd btcpayserver-docker
./bitcoin-lightning-cli.sh

E.g. to list all commands: ./bitcoin-lightning-cli.sh help or show info about the node ./bitcoin-lightning-cli.sh getinfo

Lapps (Lightning Network Apps)

Lapps are applications built on top of the Lightning Charge, a complimentary package that allows users and developers to easier use and develop on top of c-lightning. If you decided to use c-lightning, you can easily connect your BTCPay to any of the Lapps.

BTCPay exposes all the necessary information required to connect your internal BTCPay c-lightning node to a Lightning Network App. Go to Server Settings > Services > Lightning charge server > See information > Credentials.

Below are videos that showcase how to connect some of the lapps to your BTCPay.

c-lightningbtcpay1

c-lightningbtcpay2

c-lightningbtcpay3