Motivation
Simple: saving on tx fees. First, the opening tx is smaller - for 1 input and 1 output, is is 111 vb instead of 154 vb. Second, no need to redeem that change output, which saves another 58 vb. (Assuming taproot for the input and change.)
Limitations
My method below only works for fee < 47 sats/vb. And it is rather clumsy.
How
We need 2 terminals, one for creating a tx, another one for opening the channel.
Switch to terminal 1. Choose UTXOS we want to spend.
UTXOS="--utxo <TXID>:<OUTPUT_NUM> --utxo <TXID>:<OUTPUT_NUM>"
Now we find out how much exactly we can send (after subtracting fees). We need some dummy P2WKH address (the long, 62 characters). For example, we may copy the destination address of any channel opening, I will use
bc1q4n5edfv92ux9vxja2j47xlxd94ae0cq9u6nkz3qu3uh6rnezevqsc8pru0
, which corresponds to an already closed channel between Bitrefill Routing and VN.Sovereign. It is possible to batch open several channels this way, but then we would need distinct dummy addresses. Divide your desired fee by 1.48 - so if you want fee 30 sats/vb, 30/1.48 = 20.27 , so we use --fee-rate 20
. This math only works for 1 input, you may want try various fee rates../bos fund -v --dryrun $UTXOS --fee-rate 20 bc1q4n5edfv92ux9vxja2j47xlxd94ae0cq9u6nkz3qu3uh6rnezevqsc8pru0 MAX-200 send_to: - bc1q4n5edfv92ux9vxja2j47xlxd94ae0cq9u6nkz3qu3uh6rnezevqsc8pru0: 0.06233683 requested_fee_rate: 20 sum_of_outputs: 0.06233683 spending_utxos: - [redacted] fee_tokens_per_vbyte: 29.73 signed_transaction: [redacted]
We cannot spend
MAX
, we would get error (not enough funds, ironically) we need to spend MAX - 10*<fee_rate>
. Watch the send_to:
section, whether there is a change output - not our case. Copy the amount and convert it from BTC to sats , we get 0.06233683 BTC = 6233683 sats. Bos always uses 8 decimals, so we can just copy the decimal part.Switch to terminal 2 and initiate a channel opening with the amount we obtained, and using
--external-funding
flag. This is a bit counter-intuitive, we are really doing internal funding, just controlled by us. The node ID used is Bitrefill Routing../bos open --type public --external-funding --amount 6233683 030c3f19d742ca294a55c00376b3b355c3c90d61c6b6b39554dbc7ac19b141c14f - node: Bitrefill Routing channels_per_peer: 1.09 is_accepting_large_channels: true opening_to: - Bitrefill Routing: 0.06233683 connecting_to: alias: Bitrefill Routing public_key: 030c3f19d742ca294a55c00376b3b355c3c90d61c6b6b39554dbc7ac19b141c14f funding_deadline: Today at 12:56 PM fund: fund bc1qucuz7nufnc5yku7d4dy5ltaspk3u6gpk4cth5687swhssj5mkxks2fa7jr 6233683 bc1qucuz7nufnc5yku7d4dy5ltaspk3u6gpk4cth5687swhssj5mkxks2fa7jr, 0.06233683 ? Enter signed transaction or PSBT that pays 0.06233683 to bc1qucuz7nufnc5yku7d4dy5ltaspk3u6gpk4cth5687swhssj5mkxks2fa7jr or press enter to cancel funding.
Copy the address and amount (line 17) and go back to terminal 1. Use the previous
fund
command, but delete --dry-run
and use the address and amount from previous step instead of dummy address. Triple check here, you are now creating a real tx, although not broadcasting it yet../bos fund -v $UTXOS --fee-rate 20 bc1qucuz7nufnc5yku7d4dy5ltaspk3u6gpk4cth5687swhssj5mkxks2fa7jr 6233683 send_to: - bc1qucuz7nufnc5yku7d4dy5ltaspk3u6gpk4cth5687swhssj5mkxks2fa7jr: 0.06233683 requested_fee_rate: 20 sum_of_outputs: 0.06233683 spending_utxos: - [redacted] fee_tokens_per_vbyte: 29.73 signed_transaction: 020... [redacted]
You may check the signed transaction for example by importing it to electrum (menu->tools->load transaction->from text) to check that you are sending to address(es) given by
bos open
.Copy the signed transaction to clipboard, switch to terminal 1, and paste it here.
Future
lnd openchannel
has a new flag --fundmax
, which tries to spend all funds in the lnd's onchain wallet. I tried to "lease" (lock) all my UTXOs except one or two, but it insisted on creating a 100k change as reserve for anchor channels. Even when I left a 100k UTXO unlocked, it spent it and created 100k change.This PR should implement it directly in lnd.
chantools genimportscript -/format bitcoin-descriptors
, and import the private key you want in e.g. electrum, and then create funding tx with electrum. But this rules out taproot outputs because electrum does not support them. And I tried importing the file from chantools bybitcoin-cli importwallet
, but did not succeed.bos open
as in the original post) and send from Sparrow to address given bybos open
.