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

Transaction Creation

With a Wollet you can generate an address, which can be used to receive some funds. You can fetch the transactions receiving the funds using a "client", and apply them to the wallet. Now that the Wollet has a balance, it is able to craft transactions sending funds to desired destination.

The first step is construction a TxBuilder (or WolletTxBuilder), using TxBuilder::new() or Wollet::tx_builder(). You can now specify how to build the transaction using the methods exposed by the TxBuilder.

Add a Recipient

If you want to send some funds you need this information:

  • Address: destination (confidential) address provided by the receiver
  • Amount: number of units of the asset (satoshi) to be sent.
  • Asset: identifier of the asset that should be sent

Then you can call TxBuilder::add_recipient() to create an output which sends the amount of the asset, to the specified address.

You can add multiple recipients to the same transaction.

Advanced Options

LWK allows to construct complex transactions, here there are few examples

Construct the Transaction (PSET)

Once you set all the desired options to the TxBuilder. You can construct the transaction calling TxBuilder::finish(). This will return a Partially Signed Elements Transaction (PSET), a transaction encoded in a format that facilitates sharing the transaction with signers.

Rust
let mut pset = wollet
    .tx_builder()
    .add_recipient(&address, sats, lbtc)?
    .finish()?;
Python
Javascript
const sats = BigInt(1000);
const address = new lwk.Address("<address>");
const asset = new lwk.AssetId("<asset>");

var builder = new lwk.TxBuilder(network)
builder = builder.addRecipient(address, sats, asset)
var pset = builder.finish(wollet)

Next: Sign Transaction