Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Manual Coin Selection

Manual coin selection allows you to explicitly choose which UTXOs (unspent transaction outputs) from your wallet to use when building a transaction. By default, LWK automatically add all UTXOs to cover the transaction amount and fees. However, manual coin selection gives you control over which specific UTXOs are spent, which can be useful for privacy, UTXO management, or specific transaction requirements.

When you enable manual coin selection, only the UTXOs you specify will be used. The transaction builder will not automatically add additional UTXOs, so you must ensure the selected UTXOs provide sufficient funds to cover the transaction amount and fees.

To use manual coin selection, first retrieve the available UTXOs from your wallet using Wollet::utxos(), then call TxBuilder::set_wallet_utxos() before calling finish(). The selected UTXOs must belong to the wallet generating the transaction.

The set_wallet_utxos() method takes the following argument:

  1. utxos (Vec<OutPoint>): A vector of outpoints (transaction ID and output index) identifying the UTXOs to use. Each outpoint must correspond to a UTXO owned by the wallet.

Getting Available UTXOs

Before selecting UTXOs manually, you need to retrieve the list of available UTXOs from your wallet:

Rust
let utxos = w.wollet.utxos()?;
Python
utxos = wollet.utxos()

Manual Coin Selection for L-BTC

The simplest use case is selecting specific L-BTC UTXOs for a transaction:

Rust
let sent_satoshi = 200_000;
let mut pset = w
    .tx_builder()
    .add_recipient(&node_address, sent_satoshi, policy_asset)?
    .set_wallet_utxos(vec![utxos[0].outpoint])
    .finish()?;
signer.sign(&mut pset)?;

// Broadcast the transaction
let tx = w.wollet.finalize(&mut pset).unwrap();
let tx = serialize(&tx);
Python
builder = network.tx_builder()
builder.add_lbtc_recipient(node_address, sent_satoshi)
builder.set_wallet_utxos([utxos[0].outpoint()])
unsigned_pset = builder.finish(wollet)


signed_pset = signer.sign(unsigned_pset)
finalized_pset = wollet.finalize(signed_pset)


tx = finalized_pset.extract_tx()

Manual Coin Selection with Assets

When sending assets, you must include sufficient L-BTC UTXOs to cover transaction fees. If you only select asset UTXOs without L-BTC, the transaction will fail with an InsufficientFunds error.

Next Steps

After learning about manual coin selection, you can:


Previous: Transaction Creation