Fund the wallet of a CLN Lightning node running on regtest

LNROOM #4November 29, 2022

In this episode we see how to fund a CLN lightning node running on regtest. To do so, we start 1 node on the Bitcoin regtest chain, then we create bech32 address to be used by the Lightning node internal wallet, then we send 1 Bitcoin from a Bitcoin wallet named default to the Lightning node internal wallet and finally we send back that Bitcoin to the Bitcoin wallet default.

Transcript with corrections and improvements

Hi guys, welcome to the LN Room, I'm Tony Aldon and today in this episode 4 we are going to fund a CLN lightning node running on regtest.

To do so we are going to:

  1. use the script contrib/startup_regtest.sh provided by the lightning repository to start 1 node on the Bitcoin regtest chain,

  2. create a bech32 address to be used by the Lightning node internal wallet,

  3. send 1 Bitcoin from a Bitcoin wallet named default to the Lightning node internal wallet and finally

  4. send back that Bitcoin to the Bitcoin wallet default.

This is the plan.

I hope you enjoy the video and stay with me until the end.

Let's get started.

Start 1 Lightning node running on regtest

We are in the terminal, in the lightning repository.

We source the script contrib/startup_regtest.sh and we use the provided command start_ln to start one Lightning node on regtest.

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ source contrib/startup_regtest.sh
lightning-cli is hashed (/usr/bin/lightning-cli)
lightningd is /usr/bin/lightningd
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ start_ln 1
Bitcoin Core starting
awaiting bitcoind...
Making "default" bitcoind wallet.
[1] 28975
Commands:
        l1-cli, l1-log,
        bt-cli, stop_ln, fund_nodes

This also has created a Bitcoin wallet called default as we can see by running the following command:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -getinfo
Chain: regtest
Blocks: 1
Headers: 1
Verification progress: 100.0000%
Difficulty: 4.656542373906925e-10

Network: in 0, out 0, total 0
Version: 230000
Time offset (s): 0
Proxies: n/a
Min tx relay fee rate (BTC/kvB): 0.00001000

Wallet: default
Keypool size: 4000
Transaction fee rate (-paytxfee) (BTC/kvB): 0.00000000

Balance: 0.00000000

Warnings:

For convenience, to operate on the Lightning node l1 we are going to use the alias l1-cli that just specifies the base directory of the lightning node l1 as we can see below:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l1-cli
alias l1-cli='lightning-cli --lightning-dir=/tmp/l1-regtest'

Our running node l1 is in the following state:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli getinfo | jq
{
  "id": "038be49fb645eb7dd65dadbaf5bda874fcc38717becf9caf258c08199a3878952e",
  "alias": "LOUDCHEF",
  "color": "038be4",
  "num_peers": 0,
  "num_pending_channels": 0,
  "num_active_channels": 0,
  "num_inactive_channels": 0,
  "address": [],
  "binding": [
    {
      "type": "ipv4",
      "address": "127.0.0.1",
      "port": 7171
    }
  ],
  "version": "0.12.1",
  "blockheight": 1,
  "network": "regtest",
  "fees_collected_msat": 0,
  "lightning-dir": "/tmp/l1-regtest/regtest",
  "our_features": {
    "init": "08a000080269a2",
    "node": "88a000080269a2",
    "channel": "",
    "invoice": "02000000024100"
  }
}

Mine some blocks on Bitcoin regtest

To be able to send 1 Bitcoin to the Lightning node wallet, we must first fund the Bitcoin wallet default. We do this by mining some blocks to a new created address belonging to the default wallet.

We generate a new address with the sub-command getnewaddress of bitcoin-cli.

Here we can read part of the help documentation.

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest help getnewaddress | less
getnewaddress ( "label" "address_type" )

Returns a new Bitcoin address for receiving payments.
If 'label' is specified, it is added to the address book
so payments received with the address will be associated with 'label'.

Arguments:
1. label           (string, optional, default="") The label name for the address to be linked to. It can also be set to the empty string "" to represent the default label. The label does not need to exist, it will be created if there is no label by the given name.
2. address_type    (string, optional, default=set by -addresstype) The address type to use. Options are "legacy", "p2sh-segwit", "bech32", and "bech32m".

Result:
"str"    (string) The new bitcoin address

Examples:
> bitcoin-cli getnewaddress

And by running the following command we create a new Bitcoin address associated to the default wallet:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default getnewaddress
bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d

To mine blocks we can use the sub-command generatetoaddress of bitcoin-cli as we can see looking at its help documentation:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default help generatetoaddress | less
generatetoaddress nblocks "address" ( maxtries )

Mine to a specified address and return the block hashes.

Arguments:
1. nblocks     (numeric, required) How many blocks are generated.
2. address     (string, required) The address to send the newly generated bitcoin to.
3. maxtries    (numeric, optional, default=1000000) How many iterations to try.

Result:
[           (json array) hashes of blocks generated
  "hex",    (string) blockhash
  ...
]

Examples:

Generate 11 blocks to myaddress

And with the following command we mine 100 blocks to the address bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d belonging to the default wallet:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null

An we check with the sub-command getbalance of bitcoin-cli that the balance of the default wallet is no longer null:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default getbalance
50.00000000

Send 1 Bitcoin to the Lightning node wallet

Since we have enough Bitcoin in the Bitcoin default wallet, we can now send Bitcoins from that wallet.

But before we use the sub-command sendtoaddress of bitcoin-cli to send 1 Bitcoin to the Lightning node wallet we have to generate a new address belonging the Lightning node l1.

First we check that the Lightning node l1 has balance null by running the following command:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 0,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}

To generate a new address for the Lightning node l1 we use the sub-command newaddr of lightning-cli. In the first part of its man page we can read that if we don't specify an address type as argument, the sub-command create a bech32 address.

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli help newaddr
LIGHTNING-NEWADDR(7)                                        LIGHTNING-NEWADDR(7)

NAME
       lightning-newaddr  --  Command for generating a new address to be used by
       Core Lightning

SYNOPSIS
       newaddr [ addresstype ]

DESCRIPTION
       The newaddr RPC command generates a new address which can subsequently be
       used to fund channels managed by the Core Lightning node.

       The funding transaction needs to be confirmed before funds can be used.

       addresstype  specifies the type of address wanted; i.e. p2sh-segwit (e.g.
       2MxaozoqWwiUcuD9KKgUSrLFDafLqimT9Ta     on     bitcoin     testnet     or
       3MZxzq3jBSKNQ2e7dzneo9hy4FvNzmMmt3  on  bitcoin  mainnet) or bech32 (e.g.
       tb1qu9j4lg5f9rgjyfhvfd905vw46eg39czmktxqgg   on   bitcoin   testnet    or
       bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej on bitcoin
       mainnet). The special value all generates both address types for the same
       underlying key.

       If no addresstype is specified the address generated is a bech32 address.

We generate a new bech32 address for the Lightning node l1:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli newaddr
{
   "bech32": "bcrt1qpys7yd30k2ehmq3prff67rmp0zr5vjnuwlm7rv"
}

Now we look at the help documentation of the sub-command sendtoaddress of bitcoin-cli:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default help sendtoaddress | less
sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount replaceable conf_target "estimate_mode" avoid_reuse fee_rate verbose )

Send an amount to a given address.
Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.

Arguments:
1. address                  (string, required) The bitcoin address to send to.
2. amount                   (numeric or string, required) The amount in BTC to send. eg 0.1
3. comment                  (string, optional) A comment used to store what the transaction is for.
                            This is not part of the transaction, just kept in your wallet.
4. comment_to               (string, optional) A comment to store the name of the person or organization
                            to which you're sending the transaction. This is not part of the
                            transaction, just kept in your wallet.

An we can finally send 1 Bitcoin from the Bitcoin wallet default to the Lightning node internal wallet by running the following command:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default sendtoaddress bcrt1qpys7yd30k2ehmq3prff67rmp0zr5vjnuwlm7rv 1
e257b86466ee4c182657646b44d27118e0353c44325e7eb89f4b22c3a7f80d5d

The balance of the Lightning node wallet is still null as we can see in the following snippet:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 0,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}

This is because the previous transaction e257b86466ee4c182657646b44d27118e0353c44325e7eb89f4b22c3a7f80d5d has not been mined in a block so far. This is normal, because we are running the Bitcoin regtest chain manually and we have to mine blocks with the command generatetoaddress as we did before. In the following command we mine 100 block to the address bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null

But we still have the Lightning node wallet of l1 null:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 0,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}

It seems that we haven't enough blocks. Let's mine 100 blocks more.

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null

Finally, we have our Lightning node wallet funded with 1 Bitcoin as we can see below:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 100000000000,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}

Withdraw funds from our Lightning node wallet

We can see in the man page of the sub-command withdraw of lihgtning-cli that if we pass the string all as value for the amount we want to withdraw, all the funds in the Lightning node wallet are withdrawn:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli help withdraw
LIGHTNING-WITHDRAW(7)                                      LIGHTNING-WITHDRAW(7)

NAME
       lightning-withdraw  --  Command  for  withdrawing funds from the internal
       wallet

SYNOPSIS
       withdraw destination satoshi [feerate] [minconf] [utxos]

DESCRIPTION
       The withdraw RPC command sends funds from Core Lightning's internal  wal-
       let to the address specified in destination.

       The address can be of any Bitcoin accepted type, including bech32.

       satoshi   is  the  amount  to  be  withdrawn  from  the  internal  wallet
       (expressed, as name suggests, in satoshi). The string all can be used  to
       specify  withdrawal  of  all available funds. Otherwise, it is in satoshi
       precision; it can be a whole number, a whole  number  ending  in  sat,  a
       whole  number  ending  in 000msat, or a number with 1 to 8 decimal places
       ending in btc.

This what we do in the following command. We withdraw all the funds from the Lightning node wallet of l1 to the address bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d belonging to the Bitcoin default wallet:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli withdraw bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d all
{
   "tx": "02000000015d0df8a7c3224b9fb87e5e32443c35e01871d2446b645726184cce6664b857e20000000000fdffffff0192e0f50500000000160014ad6939db1d871dad1500867f6d8882e4e8a173dd2d010000",
   "txid": "a5afdd3197e1cb9b0dcff6ac495121bcfeb35a26167d0e07c560735f4ee38847",
   "psbt": "cHNidP8BAFICAAAAAV0N+KfDIkufuH5eMkQ8NeAYcdJEa2RXJhhM7mZkuFfiAAAAAAD9////AZLg9QUAAAAAFgAUrWk52x2HHa0VAIZ/bYiC50ihc90tAQAAAAEA3gIAAAAAAQF/Nd+luHumiNn+QACv3TscWwQGyWRNQtv18c5ZwWLbigAAAAAA/v///wIA4fUFAAAAABYAFAkh4jYvsrN9giEaU68PYXiHRkp8cxAQJAEAAAAWABSU7MkylzyJZs9DGjLZQ9OZa2aaAgJHMEQCICo4v21QUjrqs4rGSqFAguAU65BN97qYeF7rt+m6wepwAiAZKnj+ZRoYgnUduLHhRfbkiMCb1u7Gik2oHQQuBB0n3wEhA0fJllYPpe4ZhARYSsM/jyJE62KBv1eJpx/yi5BRjMrzXwAAAAEBHwDh9QUAAAAAFgAUCSHiNi+ys32CIRpTrw9heIdGSnwiAgLmoHytOcWYfMPjEaj2+PP0TYyBL6qbstH9UPZJeSCAAEcwRAIgF7Ldz60c5JkmXR65FxZUB8t1B0mwTgy7vlytXN1Vc5kCIFHg/OjMXfYwTkfsTHKIJWbtzjXKIeR2keok0sKCQktUASIGAuagfK05xZh8w+MRqPb48/RNjIEvqpuy0f1Q9kl5IIAACAkh4jYAAAAAAAz8CWxpZ2h0bmluZwQCAAEA"
}

As we haven't mined more blocks the funds are still present in the Lightning node wallet of l1:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 100000000000,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}

Let's mine 200 blocks on the Bitcoin regtest chain and check that the balance of the Lightning node wallet of l1 is now null:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 200 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 0,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}

This is what I wanted to share with you today.

I hope you enjoy the video and if you get some value from this video, give it a thumb up and subscribe to the channel.

See you next time.

Terminal session

We ran the following commands in this order:

$ source contrib/startup_regtest.sh
$ start_ln 1
$ bitcoin-cli -regtest -getinfo
$ alias l1-cli
$ l1-cli getinfo | jq
$ bitcoin-cli -regtest help getnewaddress | less
$ bitcoin-cli -regtest -rpcwallet=default getnewaddress
$ bitcoin-cli -regtest -rpcwallet=default help generatetoaddress | less
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null
$ bitcoin-cli -regtest -rpcwallet=default getbalance
$ l1-cli bkpr-listbalances
$ l1-cli help newaddr
$ l1-cli newaddr
$ bitcoin-cli -regtest -rpcwallet=default help sendtoaddress | less
$ bitcoin-cli -regtest -rpcwallet=default sendtoaddress bcrt1qpys7yd30k2ehmq3prff67rmp0zr5vjnuwlm7rv 1
$ l1-cli bkpr-listbalances
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null
$ l1-cli bkpr-listbalances
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null
$ l1-cli bkpr-listbalances
$ l1-cli help withdraw
$ l1-cli withdraw bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d all
$ l1-cli bkpr-listbalances
$ bitcoin-cli -regtest generatetoaddress 200 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null
$ l1-cli bkpr-listbalances

And below you can read the terminal session (command lines and outputs):

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ source contrib/startup_regtest.sh
lightning-cli is hashed (/usr/bin/lightning-cli)
lightningd is /usr/bin/lightningd
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ start_ln 1
Bitcoin Core starting
awaiting bitcoind...
Making "default" bitcoind wallet.
[1] 28975
Commands:
        l1-cli, l1-log,
        bt-cli, stop_ln, fund_nodes
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -getinfo
Chain: regtest
Blocks: 1
Headers: 1
Verification progress: 100.0000%
Difficulty: 4.656542373906925e-10

Network: in 0, out 0, total 0
Version: 230000
Time offset (s): 0
Proxies: n/a
Min tx relay fee rate (BTC/kvB): 0.00001000

Wallet: default
Keypool size: 4000
Transaction fee rate (-paytxfee) (BTC/kvB): 0.00000000

Balance: 0.00000000

Warnings:
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l1-cli
alias l1-cli='lightning-cli --lightning-dir=/tmp/l1-regtest'
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli getinfo | jq
{
  "id": "038be49fb645eb7dd65dadbaf5bda874fcc38717becf9caf258c08199a3878952e",
  "alias": "LOUDCHEF",
  "color": "038be4",
  "num_peers": 0,
  "num_pending_channels": 0,
  "num_active_channels": 0,
  "num_inactive_channels": 0,
  "address": [],
  "binding": [
    {
      "type": "ipv4",
      "address": "127.0.0.1",
      "port": 7171
    }
  ],
  "version": "0.12.1",
  "blockheight": 1,
  "network": "regtest",
  "fees_collected_msat": 0,
  "lightning-dir": "/tmp/l1-regtest/regtest",
  "our_features": {
    "init": "08a000080269a2",
    "node": "88a000080269a2",
    "channel": "",
    "invoice": "02000000024100"
  }
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest help getnewaddress | less
getnewaddress ( "label" "address_type" )

Returns a new Bitcoin address for receiving payments.
If 'label' is specified, it is added to the address book
so payments received with the address will be associated with 'label'.

Arguments:
1. label           (string, optional, default="") The label name for the address to be linked to. It can also be set to the empty string "" to represent the default label. The label does not need to exist, it will be created if there is no label by the given name.
2. address_type    (string, optional, default=set by -addresstype) The address type to use. Options are "legacy", "p2sh-segwit", "bech32", and "bech32m".

Result:
"str"    (string) The new bitcoin address

Examples:
> bitcoin-cli getnewaddress
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default getnewaddress
bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default help generatetoaddress | less
generatetoaddress nblocks "address" ( maxtries )

Mine to a specified address and return the block hashes.

Arguments:
1. nblocks     (numeric, required) How many blocks are generated.
2. address     (string, required) The address to send the newly generated bitcoin to.
3. maxtries    (numeric, optional, default=1000000) How many iterations to try.

Result:
[           (json array) hashes of blocks generated
  "hex",    (string) blockhash
  ...
]

Examples:

Generate 11 blocks to myaddress
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default getbalance
50.00000000
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 0,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli help newaddr
LIGHTNING-NEWADDR(7)                                        LIGHTNING-NEWADDR(7)

NAME
       lightning-newaddr  --  Command for generating a new address to be used by
       Core Lightning

SYNOPSIS
       newaddr [ addresstype ]

DESCRIPTION
       The newaddr RPC command generates a new address which can subsequently be
       used to fund channels managed by the Core Lightning node.

       The funding transaction needs to be confirmed before funds can be used.

       addresstype  specifies the type of address wanted; i.e. p2sh-segwit (e.g.
       2MxaozoqWwiUcuD9KKgUSrLFDafLqimT9Ta     on     bitcoin     testnet     or
       3MZxzq3jBSKNQ2e7dzneo9hy4FvNzmMmt3  on  bitcoin  mainnet) or bech32 (e.g.
       tb1qu9j4lg5f9rgjyfhvfd905vw46eg39czmktxqgg   on   bitcoin   testnet    or
       bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej on bitcoin
       mainnet). The special value all generates both address types for the same
       underlying key.

       If no addresstype is specified the address generated is a bech32 address.
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli newaddr
{
   "bech32": "bcrt1qpys7yd30k2ehmq3prff67rmp0zr5vjnuwlm7rv"
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default help sendtoaddress | less
sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount replaceable conf_target "estimate_mode" avoid_reuse fee_rate verbose )

Send an amount to a given address.
Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.

Arguments:
1. address                  (string, required) The bitcoin address to send to.
2. amount                   (numeric or string, required) The amount in BTC to send. eg 0.1
3. comment                  (string, optional) A comment used to store what the transaction is for.
                            This is not part of the transaction, just kept in your wallet.
4. comment_to               (string, optional) A comment to store the name of the person or organization
                            to which you're sending the transaction. This is not part of the
                            transaction, just kept in your wallet.
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default sendtoaddress bcrt1qpys7yd30k2ehmq3prff67rmp0zr5vjnuwlm7rv 1
e257b86466ee4c182657646b44d27118e0353c44325e7eb89f4b22c3a7f80d5d
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 0,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 0,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 100000000000,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli help withdraw
LIGHTNING-WITHDRAW(7)                                      LIGHTNING-WITHDRAW(7)

NAME
       lightning-withdraw  --  Command  for  withdrawing funds from the internal
       wallet

SYNOPSIS
       withdraw destination satoshi [feerate] [minconf] [utxos]

DESCRIPTION
       The withdraw RPC command sends funds from Core Lightning's internal  wal-
       let to the address specified in destination.

       The address can be of any Bitcoin accepted type, including bech32.

       satoshi   is  the  amount  to  be  withdrawn  from  the  internal  wallet
       (expressed, as name suggests, in satoshi). The string all can be used  to
       specify  withdrawal  of  all available funds. Otherwise, it is in satoshi
       precision; it can be a whole number, a whole  number  ending  in  sat,  a
       whole  number  ending  in 000msat, or a number with 1 to 8 decimal places
       ending in btc.
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli withdraw bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d all
{
   "tx": "02000000015d0df8a7c3224b9fb87e5e32443c35e01871d2446b645726184cce6664b857e20000000000fdffffff0192e0f50500000000160014ad6939db1d871dad1500867f6d8882e4e8a173dd2d010000",
   "txid": "a5afdd3197e1cb9b0dcff6ac495121bcfeb35a26167d0e07c560735f4ee38847",
   "psbt": "cHNidP8BAFICAAAAAV0N+KfDIkufuH5eMkQ8NeAYcdJEa2RXJhhM7mZkuFfiAAAAAAD9////AZLg9QUAAAAAFgAUrWk52x2HHa0VAIZ/bYiC50ihc90tAQAAAAEA3gIAAAAAAQF/Nd+luHumiNn+QACv3TscWwQGyWRNQtv18c5ZwWLbigAAAAAA/v///wIA4fUFAAAAABYAFAkh4jYvsrN9giEaU68PYXiHRkp8cxAQJAEAAAAWABSU7MkylzyJZs9DGjLZQ9OZa2aaAgJHMEQCICo4v21QUjrqs4rGSqFAguAU65BN97qYeF7rt+m6wepwAiAZKnj+ZRoYgnUduLHhRfbkiMCb1u7Gik2oHQQuBB0n3wEhA0fJllYPpe4ZhARYSsM/jyJE62KBv1eJpx/yi5BRjMrzXwAAAAEBHwDh9QUAAAAAFgAUCSHiNi+ys32CIRpTrw9heIdGSnwiAgLmoHytOcWYfMPjEaj2+PP0TYyBL6qbstH9UPZJeSCAAEcwRAIgF7Ldz60c5JkmXR65FxZUB8t1B0mwTgy7vlytXN1Vc5kCIFHg/OjMXfYwTkfsTHKIJWbtzjXKIeR2keok0sKCQktUASIGAuagfK05xZh8w+MRqPb48/RNjIEvqpuy0f1Q9kl5IIAACAkh4jYAAAAAAAz8CWxpZ2h0bmluZwQCAAEA"
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 100000000000,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 200 bcrt1q445nnkcasuw669gqselkmzyzun52zu7a9jhl2d > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli bkpr-listbalances
{
   "accounts": [
      {
         "account": "wallet",
         "balances": [
            {
               "balance_msat": 0,
               "coin_type": "bcrt"
            }
         ]
      }
   ]
}

Resources