Closing out Lightning to Bitcoin

Maybe you’ve decided that you want to close down your old computer that was running a Lightning network node, but you haven’t decided to stop using Bitcoin. Maybe you just need to pay for an unexpected expense. Maybe anything. The question becomes: How do you take the BTC you currently have linked into a Lightning wallet and shoot it back off to a Bitcoin main wallet? I didn’t find that readily available anywhere and clearly listed, so here you go. 🙂

Verify Balances

First things first… you’ll need to close down your channels (basically stop having a held commitment). You can check what channels you have open with a quick command (“listchannels”)… and of course none of this is real data, as I’ve swapped out pubkeys, channel points, etc with dummy data (i.e. the pubkey and channel point are consistent throughout this for demonstration, but don’t have three dots in the middle of them, etc).

BlockChainy@system:~$ lncli listchannels
{
    "channels": [
        {
            "active": false,
            "remote_pubkey": "03e52c...abc123",
            "channel_point": "abc123...fedcba:0",
            "chan_id": "NUMBERS",
            "capacity": "#VALUE",
            "local_balance": "#VALUE",
            "remote_balance": "#VALUE",
            ... etc ...
        },
       {
            "active": false,
            "remote_pubkey": "02f41d...abc123",
            "channel_point": "abc123...fedcba:1",
            "chan_id": "NUMBERS",
            "capacity": "#VALUE",
            "local_balance": "#VALUE",
            "remote_balance": "#VALUE",
            ... etc ...
        }
    ]
}

In the example above we have two active channels. We could close each individually, but in this case we’re just looking to shut it all down so let’s close all channels with the cleverly named command “closeallchannels” (and confirm each with “yes”):

BlockChainy@system:~$ lncli closeallchannels
Unilaterally close channel with node 03e52...abc123 and channel point abc123...fedcba:0? The closing transaction will need #NUMBER confirmations before the funds can be spent. (yes/no): yes
Unilaterally close channel with node 02f41d...abc123 and channel point abc123...fedcba:1? The closing transaction will need #NUMBER confirmations before the funds can be spent. (yes/no): yes
{
        "remote_pub_key": "03e52c...abc123",
        "channel_point": "abc123...fedcba:0",
        "closing_txid": "deadbeef...feedbeef",
        "error": ""
}
{
        "remote_pub_key": "02f41d...abc123",
        "channel_point": "abc123...fedcba:1",
        "closing_txid": "feedbeef...deadbeef",
        "error": ""
}

As soon as that’s done you can check to see the status (hopefully no error messages were presented). You can also, of course, track the status of those closures using the transaction ID 9 (txid). To check status. First we’ll check to make sure no channels are still active, then we’ll check the wallet balance:

BlockChainy@system:~$ lncli listchannels
{
    "channels": [
    ]
}
BlockChainy@system:~$ lncli walletbalance
{
    "total_balance": "1234567",
    "confirmed_balance": "1234567",
    "unconfirmed_balance": "0",
    "account_balance": {
        "default": {
            "confirmed_balance": "1234567",
            "unconfirmed_balance": "0"
        }
    }
}

Remember that part above that was marked as #NUMBER? Well, that’s how many blocks have to complete before everything settles out. Kick back and wait for awhile. 🙂 Once those blocks have completed, you can now send everything to a Bitcoin address of your choosing as follows:

BlockChainy@system:~$ lncli sendcoins --sweepall BTC_ADDRESS

{
    "txid": "fadedbeef...deadbee7"
}
BlockChainy@system:~$ lncli walletbalance
{
    "total_balance": "0",
    "confirmed_balance": "0",
    "unconfirmed_balance": "0",
    "account_balance": {
        "default": {
            "confirmed_balance": "0",
            "unconfirmed_balance": "0"
        }
    }
}

You can now track the final progression out to whatever address you sent using any Blockchain explorer, such as https://www.blockchain.com/btc/tx/fadedbeef…deadbee7

That’s all for today… as always, good hunting. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: