The Lightning Network can be used with any node software that supports SegWit. In this example, we'll demonstrate the steps to install Lightning with Bitcoin Core. This guide is intended to merely demonstrate specific commands for using this node with CAS.
STOP - if you need an introduction to Lightning. Please learn the intricacies & nuances of the Lightning network at introductory sites such as: https://bitcoiner.guide/lightning/
This article is not intended to describe usage of the Lightning Network or transmission/receipt of payments.
Add the correct credentials for bitcoind.rpcuser and bitcoind.rpcpass (determined during your Bitcoin Core installation). LND uses the RPC credentials to communicate with Bitcoin Core.
Note: the “restlisten” port is an important CAS parameter, and can be changed (as needed) to avoid conflicts with other services that may be running on your node server.
Save & exit nano (Ctrl-X).
Start the node.
The node will pause & protest that that the wallet is locked. You’ll need to create one (next).
If you already have a LN wallet, open the wallet (when requested) and skip the next step.
Create a new LN wallet.
Open another terminal window. The node (lnd) must continue to run in the background. The screen utility (or tmux) is perfect for this, or you may use 2 separate terminal windows - either way will work.
Enter a new password. You’ll need this password every time you start the node, so make it memorable.
The Lightning node will now begin synchronizing. It won’t take very long, and it depends upon the underlying Bitcoin node. Both nodes must operate simultaneously.
You’ll need to unlock the wallet every time you start/restart the Lightning node.
Create a new deposit address.
A deposit address is required to add BTC to fund your LN wallet. You may create as many deposit addresses as you like; they all fund the same LN node.
lncli newaddress p2wkh
Creates a “Pay to witness key hash”, to which you’ll send Bitcoin to fund a channel (put BTC in escrow).
A Lightning Channel is a type of temporary ledger that commits a certain amount of Bitcoin to all the contained, aggregate transactions. Think of it as a deposit, an amount that’s held in escrow until the channel is closed. When the channel closes, the tallies are committed to the Bitcoin blockchain (resulting in a finalizing transaction with normal BTC mining fees).
Fund the new wallet.
Use: lncli channelbalance to view any existing balances already committed to a channel.
If you have not yet funded your wallet, send a small amount of Bitcoin to the address created in the previous step. The minimum amount is 0.0002 BTC (= 20,000 Satoshis).
Wait for the requisite confirmations (normally 3), then check your funding wallet balance:
in this example, I’ve sent 20000 Satoshis to my funding wallet.
We’ll use this info (from the Lightning explorer website) to extract 2 required channel details.
public key = 03e35a27fa8bfad8675aeb9e96530e7b00e6fa03b571d235f6b4e68cfb4ef9097c
node address = 188.8.131.52:9736
The final required piece is the amount. You’ll have to commit a certain amount to the initial transaction, and this will be locked up (you can’t spend the Bitcoin) until the final transaction is broadcast. If you commit 20,000 Satoshis to the channel, then that is the maximum amount you can send back & forth. Normally, you’ll commit the largest expected transaction amounts (in Satoshis) to the channel.
The minimum amount required to open a channel is 20,000 Satoshis (.0002 BTC).
There is no maximum (except what you commit to the funding transaction).
Many channels require a minimum of 500,000 Satoshis (.005 BTC).
In this example, we’ll commit the trivial amount of 20000 Satoshis. This is the resulting command:
A very important concept to understand here is that the channel is composed of 2 Bitcoin transactions: an opening transaction (funding) and a closing transaction. The Bitcoin doesn’t “settle up” in the final transaction until the Lightning Channel is closed. There are a number of ways this may happen, some deliberate - some not - but it must be closed to release your BTC funding tx. It will be tied up in the channel until that event.
When the channel is closed, it may take up to 2 weeks before the final transaction is posted!
If successful, the request will return the funding transaction ID:
At any time, check your channel state using the lncli listchannels command demonstrated (above). It will take a certain amount of time to open the channel, but once it confirms (and activates), you’ll see an active channel as shown here, using:
no channels listed probably means the channel is still pending. It may take hours+ to confirm.
use lncli pendingchannels to examine the situation (and other channels that might also be in limbo - such as closed channels).
The channel will also automatically deduct the closing transaction’s mining fees from your deposit.
e.g. while 20,000 satoshis were deposited, only the local_balance (19,273 satoshis) were available for spending. The current estimated mining fees (727 satoshis) for the closing transaction - are withheld.
Until a channel is fully opened, you cannot use your node for transactions!
Your Lightning node is now up & running.
Next, configure your Lightning node for specific use with CAS.
Setup a secure tunnel for encrypted communication:
The GB Wallet Tunnel is recommended:
General Bytes has incorporated an open-source ssh client into CAS.
Here’s the gory details - in the event you want those instead.
The first parameter is the URL, and it depends upon your implementation.
Common between both implementations is the “restlisten=” port you set in the ~/.lnd/lnd.conf file (step 8 way at the beginning). The example supplied port “8088”, so if you haven’t deviated from the examples, then we know it’s “8088”. To be certain, you may execute this:
If the result is empty, STOP. You better restart from the beginning.
Whatever number is returned is the port you’ll need to append to the URL.
The URL will be https://127.0.0.1 if you used the “EXPERTS ONLY” option in the previous step, otherwise the URL will include the public IP of your node server. So, if your public IP is “184.108.40.206”, then the URL will be: https://220.127.116.11
Finally, append the port to the URL:
The contents of these 2 files must be converted & entered as hex in the CAS parameters:
Create (or modify) a Crypto Setting for use with your lnd node.
Select “lnd” as your “Hot Wallet Buy” provider, and
enter the parameters (assembled above).
If implemented (highly recommended) enable the Wallet Tunnel and enter the password.
Green means “go”.
Now you know that CAS is communicating with your Lightning node, it’s time for final leg - if you operate your own Standalone CAS.
GB Cloud customers: you are done! The next section does not apply to you.
LNURL - for Standalone CAS Operators (only)
The next step is to enable Lightning wallets to interact with your CAS. Lightning is different from other coins; it will ask for the wallet address after inserting the fiat. CAS will communicate with your node and your customer’s wallet in separate channels while creating this transaction.
A Lightning BUY will request the Lightning QR code after the cash is inserted.
Expose the LNURL on your CAS server:
Open inbound port 7743 to all traffic.
After implementing LN in Crypto Settings, a new HTTPS REST service will begin listening on: