How to open a channel
No matter what your node purpose is, you're going to want to open a channel.
We're going to use The Megalith Node for this example.
The Megalith Node is one the biggest routing nodes on the Lighting Network. It has well-capitalized channels with most of the big players on the Network, so it's a good choice as a first channel, to allow you to send payments without problems.
Connect to the Megalith node
Open a new terminal window, navigate to the workspace/lightning
directory, and launch a command line inside the running LND container, with this script:
./exec-lncli.sh
We're going to start by just connecting to The Megalith Node. This process sets up communication between the two nodes. Use this command
lncli connect 0322d0e43b3d92d30ed187f4e101a9a9605c3ee5fc9721e6dac3ce3d7732fbb13e@164.92.106.32:9735
If the connection was successful, the only response you should get is an empty object, this:
{}
Great, before we open the channel, go head and look at the "help" for the openchannel
command:
lncli openchannel --help
There is a lot in the help for this command, but time that you spend reading the output will be a good investment in your overall understanding of the Network.
Review LND's wallet balance before we open a channel
I find it helps to review your wallet balance immediately before and immediately after opening a channel.
Let's look at our current wallet balance.
lncli walletbalance
{
"total_balance": "6000000",
"confirmed_balance": "6000000",
"unconfirmed_balance": "0",
"locked_balance": "0",
"reserved_balance_anchor_chan": "0",
"account_balance": {
"default": {
"confirmed_balance": "6000000",
"unconfirmed_balance": "0"
}
}
}
Good! This still shows that we have 6,000,000 Satoshis (0.06 BTC) in confirmed_balance
in the node's wallet, which is the same amount we deposited earlier in this tutorial.
Review the command we will use
Here is the command, with only the values we must specify:
lncli openchannel --connect 164.92.106.32:9735 --node_key 0322d0e43b3d92d30ed187f4e101a9a9605c3ee5fc9721e6dac3ce3d7732fbb13e --local_amt 5000000
Let's talk about each of these values:
--node_key
is to specify the unique public key for the Megalith Node
--connect
is to specify the network address, in the format address:port
, for the Megalith Node
--local_amt
is the amount in Satoshis to specify the size of the channel. 5,000,000 Satoshis is equal to 0.05 BTC.
Follow this pattern when opening channels
I have a preferred pattern that I use when opening channels which helps me keep track of what is going on, and catch issues. You don't have to always to it this way, but do it with me once.
- Paste the above
lncli openchannel
command into the command line. When you are ready, press ENTER. - You will see a
funding_txid
in the output, which should look like this:
{
"funding_txid": "bdbdf8f4bf49d71a0e3e9426fbb7b1f32ed2d8003132562685c2f5d3e4e82a6c"
}
- Copy the
funding_txid
to your clipboard. - Go to mempool.space, or any other block explorer.
- Paste the transaction ID into the search box.
- You should reach a page similar to this one, which shows the status of your transaction.
- Go back to your terminal, and run
lncli walletbalance
. You should see an output like this:
{
"total_balance": "998460",
"confirmed_balance": "0",
"unconfirmed_balance": "998460",
"locked_balance": "0",
"reserved_balance_anchor_chan": "10000",
"account_balance": {
"default": {
"confirmed_balance": "0",
"unconfirmed_balance": "998460"
}
}
}
Understand your on-chain balance after a channel opening
At first, this output might be confusing. I'm here to explain it for you.
First, you need to understand that the lncli walletbalance
command only looks at BTC that you have in your "on-chain" wallet -- that is, funds you could use to open channels, or could send via regular BTC transactions.
So from the perspective of walletbalance
, the 5,000,000 Satoshis, that you used to open the channel, are considered "unavailable". They won't become available again until you (or your channel partner) closes the channel.
Why I am I missing some Satoshis?
You can see in the above output that the unconfirmed_balance
is 998,460... So, if started with a 6,000,000 balance, and opened a 5,000,000 channel, shouldn't we have 1,000,000
left over?
Let's look at the output of our block explorer to understand what happened.
At the top-right of the screenshot (1), we can see that the fee that we paid to open the channel was 1,540
Satoshis. This amount is also reflected on the bottom-right of the screenshot (2), where we see a "change" output of 0.00998460. As it happens, this matches our unconfirmed_balance
of 998,460 Satoshis!
Bitcoin transactions often include "change" outputs to direct some funds back to the original wallet. If you're not 100% on this whole "change output" thing, watch a few videos on it.
Finally, are you wondering why this transaction is considered "unconfirmed"? You'll notice at the upper-left of the screenshot, the text ETA In ~29 Minutes
. This means that this block explorer is estimating that, given the fees offered in the transaction, that the transaction is likely to confirm in about this ("29 Minutes") amount of time.
How do I know when my channel is fully confirmed?
Here are three ways you can check if a channel opening transaction has confirmed:
- You can run
lncli walletbalance
, and you see that yourtotal_balance
andconfirmed_balance
are the same, like:
"total_balance": "998460",
"confirmed_balance": "998460",
- You can check a block explorer, and see that the transaction is labeled as confirmed:
- You can run
lncli listchannels
, and see that the channel is confirmed asactive
$ lncli listchannels
{
"channels": [
{
"active": true,
"remote_pubkey": "0322d0e43b3d92d30ed187f4e101a9a9605c3ee5fc9721e6dac3ce3d7732fbb13e",
"channel_point": "bdbdf8f4bf49d71a0e3e9426fbb7b1f32ed2d8003132562685c2f5d3e4e82a6c:1",
"chan_id": "920761823520686081",
"capacity": "5000000",
Public vs Private channels
In this example, we opened a public channel, which is generally what you will want to do. If a channel is public, it is announced to other nodes on the network, so that those nodes could send payments through this channel, and you can earn fees.
A private channel is not announced, so you alone could send payments through it.
If you are opening a channel for your own use only, and don't want other nodes on the Network to use it, you should open a private channel. You can do this with the same lncli
command, but just include the flag --private
Confirm your channel.backup has uploaded to your cloud storage
This is the first time you've opened a channel, so we need to confirm that your channel.backup
file has uploaded to your cloud storage.
Assuming you've followed this tutorial from the beginning, your pworker
container, that you set up in the disaster recovery step, should have been running, and should have uploaded your channel.backup
file to your cloud storage.
Before you proceed from here, it's important that you check your S3 bucket (or other storage, if you modified the script), and confirm you see a file, created at the same time that you opened the channel, with a name like 35bdbc-channel.backup
. If you see that file, your disaster recovery strategy is working!