Send All Funds

Sending all funds (also called "draining" the wallet) allows you to send all LBTC (policy asset) from your wallet to a specified address in a single transaction

Send All Funds

Sending all funds (also called "draining" the wallet) allows you to send all LBTC (policy asset) from your wallet to a specified address in a single transaction. This is useful when you want to empty your wallet, consolidate UTXOs, or transfer all funds to another address.

When you drain a wallet, all available LBTC UTXOs are selected as inputs, and after deducting transaction fees, the remaining amount is sent to the destination address. Note that draining only affects LBTC (the policy asset).

"Drain" is only available for the asset used to pay fees (LBTC) with. For LBTC it's hard to guess the right amount to send all funds: it's the sum of all LBTC inputs minus the fee, but you don't know the actual fee until you created the transaction. So we need a way specify the TxBuilder to send all LBTC.

For assets that are not LBTC, the caller can easily compute the sum of all asset in input and set the satoshi value explicitly.

To send all LBTC, use TxBuilder::drain_lbtc_wallet(). By default LBTC are sent to a wallet address, if you want specify the destination address use TxBuilder::drain_lbtc_to().

The methods take the following arguments:

  1. drain_lbtc_wallet(): No arguments. Selects all available LBTC UTXOs from the wallet to be spent.
  2. drain_lbtc_to(address): Takes an Address parameter specifying where to send all the LBTC after fees are deducted.
let address = env.elementsd_getnewaddress();
let mut pset = wollet
    .tx_builder()
    .drain_lbtc_wallet()
    .drain_lbtc_to(address.clone())
    .finish()?;
# Create a PSET sending all LBTC to the node address
builder = network.tx_builder()
builder.drain_lbtc_wallet()
builder.drain_lbtc_to(node_addr)
pset = builder.finish(wollet)
	// Create a PSET sending all LBTC to the node address
	builder := network.TxBuilder()
	if err := builder.DrainLbtcWallet(); err != nil {
		log.Fatal(err)
	}
	if err := builder.DrainLbtcTo(nodeAddr); err != nil {
		log.Fatal(err)
	}
	pset, err := builder.Finish(wollet)
	if err != nil {
		log.Fatal(err)
	}

Next Steps

After sending all funds, you can:

  • Send other assets using regular transaction creation
  • Receive new funds at any address in your wallet

Previous: Burn


Did this page help you?

The Liquid Network is a Bitcoin layer-2 enabling the issuance of security tokens and other digital assets.

© 2023 Liquid Network
All rights reserved.

Feedback and Content Requests

We'd be happy to hear your suggestions on how we can improve this site.

BuildOnL2 Community

The official BuildOnL2 community lives
at community.liquid.net. Join us and build the future of Bitcoin on Liquid.

Telegram

Community-driven telegram group where
most of the Liquid developers hang out.
Go to t.me/liquid_devel to join.