Caravan Documentation
    Preparing search index...

    Class BtcTxOutputTemplate

    Represents a Bitcoin transaction output

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new output template for use in a Bitcoin transaction.

      Parameters

      • params: { address: string; amountSats?: string; locked?: boolean }

        The parameters for the output

        • address: string

          The Bitcoin address to send funds to

        • OptionalamountSats?: string

          The amount to send in satoshis (as a string). Optional for malleable outputs.

        • Optionallocked?: boolean

          Whether the output amount is locked (immutable)

      Returns BtcTxOutputTemplate

      If trying to create a locked output with zero amount

    Properties

    _amountSats: BigNumber

    Accessors

    Methods

    • Checks if the output is valid according to basic Bitcoin transaction rules.

      This method performs several checks to ensure the output is properly formed:

      1. For locked outputs:

        • Ensures that a non-zero amount is specified.
        • Throws an error if the amount is zero, as locked outputs must always have a valid amount.
      2. For all output types:

        • Checks if the output has a non-zero amount (via hasAmount() method).
        • Verifies that the address is not an empty string.

      Note: This method does not perform exhaustive validation. For more thorough checks, consider implementing a separate, comprehensive validation method.

      Special considerations:

      • OP_RETURN outputs might require different validation logic (not implemented here).
      • Zero-amount outputs for certain special cases (like Ephemeral Anchors) are not considered valid by this basic check. Implement custom logic if needed for such cases.

      Returns boolean

      True if the output is valid, false otherwise.

      If a locked output has a zero amount.

    • Locks the output, preventing further modifications to its amount.

      This method sets the malleability of the output to false. Once called, the output amount cannot be changed. If the output is already locked, this method has no effect.

      Typical use cases include:

      • Finalizing a transaction before signing
      • Ensuring that certain outputs (like recipient amounts) are not accidentally modified

      An amount must be specified before locking. This is to prevent locking an output with a zero amount, which could lead to invalid transactions.

      Returns void

      If trying to lock an output with a zero amount

    • Subtract amount from the output

      Parameters

      • amountSats: string

        Amount to subtract in satoshis (as a string)

      Returns void

      Error if trying to modify a non-malleable output or if subtracting more than the current amount