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
- Set fee rate with
TxBuilder::fee_rate()
- Manual coin selection
- External UTXOS
- Explicit inputs and outputs
- Send all LBTC
- Issuance, reissuance, burn
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.
let mut pset = wollet
.tx_builder()
.add_recipient(&address, sats, lbtc)?
.finish()?;
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