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

Add External Inputs

LWK allows to create transactions with inputs from any wallet. This is useful for collaborative transactions where multiple parties need to contribute inputs, such as in multi-party payments, atomic swaps, or when coordinating transactions between different wallets.

When you add external UTXOs to a transaction, the transaction builder will use them along with your wallet's UTXOs to cover the transaction amount and fees. The external wallet must sign the transaction separately, as these UTXOs are not owned by your wallet.

Creating External UTXOs

To use external UTXOs, you need to create an ExternalUtxo object with the necessary information from the external wallet.

Rust
// Create an external UTXO (LBTC) from the external wollet
let utxo = &external_wollet.utxos()?[0];
let txid = utxo.outpoint.txid;
let vout = utxo.outpoint.vout as usize;
let tx = external_wollet.transaction(&txid)?.expect("from utxo").tx;
let txout = tx.output[vout].clone();
let external_utxo = ExternalUtxo {
    outpoint: utxo.outpoint,
    txout,
    tx: Some(tx),
    unblinded: utxo.unblinded,
    max_weight_to_satisfy: external_wollet.max_weight_to_satisfy(),
};
Python
external_utxo = external_wollet.utxos()[0];
external_utxo = ExternalUtxo(
    external_utxo.outpoint().vout(),
    external_wollet.transactions()[0].tx(),
    external_utxo.unblinded(),
    external_wollet.max_weight_to_satisfy(),
    external_wollet.is_segwit()
)

Create PSET with external UTXOs

Once you have one or more external UTXOs, you can call TxBuilder::add_external_utxos() before calling finish(). The external wallet must later add its signature details to the PSET and sign it.

Rust
let mut pset = wollet
    .tx_builder()
    // Add external UTXO (LBTC)
    .add_external_utxos(vec![external_utxo])?
    // Send asset to the node (funded by wollet's UTXOs)
    .add_recipient(&node_address, 1, asset)?
    // Send LBTC back to external wollet
    .drain_lbtc_wallet()
    .drain_lbtc_to(external_wollet_address)
    .finish()?;
Python
builder = network.tx_builder()
# Add external UTXO (LBTC)
builder.add_external_utxos([external_utxo])
# Send asset to the node (funded by wollet's UTXOs)
builder.add_recipient(node_addr, 1, asset)
# Send LBTC back to external wollet
builder.drain_lbtc_wallet()
builder.drain_lbtc_to(external_wollet_addr)
pset = builder.finish(wollet)

Signing with External Wallets

When you include external UTXOs in a transaction, the external wallet must add its wollet details to the PSET and sign it.

Rust
signer.sign(&mut pset)?;

// To sign the external UTXO, the external wollet must
// augment the PSET with details derived from its wollet
external_wollet.add_details(&mut pset)?;
external_signer.sign(&mut pset)?;
Python
pset = external_wollet.add_details(pset)
pset = external_signer.sign(pset)

Note: The external wallet must call add_details() on the PSET before signing. This adds the necessary witness data and other information required for the external wallet to sign its inputs.

Unblinded External UTXOs

You can also spend unblinded UTXOs (explicit asset/value) as external UTXOs. These are UTXOs that have explicit asset and value fields rather than being blinded. Use Wollet::explicit_utxos() to retrieve them.