-
- All Implemented Interfaces:
public final class TxBuilder
A transaction builder.
After creating the TxBuilder, you set options on it until finally calling
.finish
to consume the builder and generate the transaction.Each method on the TxBuilder returns an instance of a new TxBuilder with the option set/added.
-
-
Constructor Summary
Constructors Constructor Description TxBuilder()
-
Method Summary
Modifier and Type Method Description final TxBuilder
addData(List<UByte> data)
Add data as an output using OP_RETURN. final TxBuilder
addRecipient(Script script, ULong amount)
Add a recipient to the internal list. final TxBuilder
setRecipients(List<ScriptAmount> recipients)
Set the list of recipients by providing a list of ScriptAmount. final TxBuilder
addUnspendable(OutPoint unspendable)
Add a utxo to the internal list of unspendable utxos. final TxBuilder
addUtxo(OutPoint outpoint)
Add an outpoint to the internal list of UTXOs that must be spent. final TxBuilder
addUtxos(List<OutPoint> outpoints)
Add the list of outpoints to the internal list of UTXOs that must be spent. final TxBuilder
doNotSpendChange()
Do not spend change outputs. final TxBuilder
manuallySelectedOnly()
Only spend utxos added by add_utxo. final TxBuilder
onlySpendChange()
Only spend change outputs. final TxBuilder
unspendable(List<OutPoint> unspendable)
Replace the internal list of unspendable utxos with a new list. final TxBuilder
feeRate(Float satPerVbyte)
Set a custom fee rate. final TxBuilder
feeAbsolute(ULong feeAmount)
Set an absolute fee. final TxBuilder
drainWallet()
Spend all the available inputs. final TxBuilder
drainTo(Script script)
Sets the address to drain excess coins to. final TxBuilder
enableRbf()
Enable signaling RBF. final TxBuilder
enableRbfWithSequence(UInt nsequence)
Enable signaling RBF with a specific nSequence value. final TxBuilderResult
finish(Wallet wallet)
Finish building the transaction. -
-
Method Detail
-
addRecipient
final TxBuilder addRecipient(Script script, ULong amount)
Add a recipient to the internal list.
-
setRecipients
final TxBuilder setRecipients(List<ScriptAmount> recipients)
Set the list of recipients by providing a list of ScriptAmount.
-
addUnspendable
final TxBuilder addUnspendable(OutPoint unspendable)
Add a utxo to the internal list of unspendable utxos. It’s important to note that the "must-be-spent" utxos added with TxBuilder.addUtxo have priority over this. See the Rust docs of the two linked methods for more details.
-
addUtxo
final TxBuilder addUtxo(OutPoint outpoint)
Add an outpoint to the internal list of UTXOs that must be spent. These have priority over the "unspendable" utxos, meaning that if a utxo is present both in the "utxos" and the "unspendable" list, it will be spent.
-
addUtxos
final TxBuilder addUtxos(List<OutPoint> outpoints)
Add the list of outpoints to the internal list of UTXOs that must be spent. If an error occurs while adding any of the UTXOs then none of them are added and the error is returned. These have priority over the "unspendable" utxos, meaning that if a utxo is present both in the "utxos" and the "unspendable" list, it will be spent.
-
doNotSpendChange
final TxBuilder doNotSpendChange()
Do not spend change outputs. This effectively adds all the change outputs to the "unspendable" list. See TxBuilder.unspendable.
-
manuallySelectedOnly
final TxBuilder manuallySelectedOnly()
Only spend utxos added by add_utxo. The wallet will not add additional utxos to the transaction even if they are needed to make the transaction valid.
-
onlySpendChange
final TxBuilder onlySpendChange()
Only spend change outputs. This effectively adds all the non-change outputs to the "unspendable" list. See TxBuilder.unspendable.
-
unspendable
final TxBuilder unspendable(List<OutPoint> unspendable)
Replace the internal list of unspendable utxos with a new list. It’s important to note that the "must-be-spent" utxos added with TxBuilder.addUtxo have priority over these. See the Rust docs of the two linked methods for more details.
-
feeAbsolute
final TxBuilder feeAbsolute(ULong feeAmount)
Set an absolute fee.
-
drainWallet
final TxBuilder drainWallet()
Spend all the available inputs. This respects filters like TxBuilder.unspendable and the change policy.
-
drainTo
final TxBuilder drainTo(Script script)
Sets the address to drain excess coins to. Usually, when there are excess coins they are sent to a change address generated by the wallet. This option replaces the usual change address with an arbitrary ScriptPubKey of your choosing. Just as with a change output, if the drain output is not needed (the excess coins are too small) it will not be included in the resulting transaction. The only difference is that it is valid to use drainTo without setting any ordinary recipients with addRecipient (but it is perfectly fine to add recipients as well). If you choose not to set any recipients, you should either provide the utxos that the transaction should spend via addUtxos, or set drainWallet to spend all of them. When bumping the fees of a transaction made with this option, you probably want to use BumpFeeTxBuilder.allowShrinking to allow this output to be reduced to pay for the extra fees.
-
enableRbf
final TxBuilder enableRbf()
Enable signaling RBF. This will use the default
nsequence
value of0xFFFFFFFD
.
-
enableRbfWithSequence
final TxBuilder enableRbfWithSequence(UInt nsequence)
Enable signaling RBF with a specific nSequence value. This can cause conflicts if the wallet's descriptors contain an "older" (OP_CSV) operator and the given
nsequence
is lower than the CSV value. If thensequence
is higher than0xFFFFFFFD
an error will be thrown, since it would not be a valid nSequence to signal RBF.
-
finish
final TxBuilderResult finish(Wallet wallet)
Finish building the transaction. Returns a TxBuilderResult.
-
-
-
-