Package 

Class TxBuilder

  • 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 Detail

      • TxBuilder

        TxBuilder()
    • Method Detail

      • 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.

      • 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.

      • 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.

      • 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 of 0xFFFFFFFD.

      • 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 the nsequence is higher than 0xFFFFFFFD an error will be thrown, since it would not be a valid nSequence to signal RBF.