Caravan Documentation
    Preparing search index...

    Class BtcTxInputTemplate

    Represents a Bitcoin transaction input template for PSBT creation. This class contains the minimal required fields and optional fields necessary for creating a valid PSBT input.

    Hierarchy (View Summary)

    Index

    Constructors

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

      Parameters

      • params: { amountSats?: string; txid: string; vout: number }

        The parameters for creating the input template

        • OptionalamountSats?: string

          The amount in satoshis. Optional since it may come from UTXO data.

        • txid: string

          The transaction ID of the UTXO being spent (in reversed byte order)

        • vout: number

          The output index within the transaction being spent

      Returns BtcTxInputTemplate

    Properties

    _amountSats: BigNumber

    Accessors

    • get redeemScript(): undefined | Buffer

      Gets the redeem script for P2SH inputs. The redeem script contains the actual spending conditions for P2SH outputs. For multisig P2SH, this is the multisig script with the signature requirements.

      Returns undefined | Buffer

    • set redeemScript(script: Buffer): void

      Sets the redeem script for P2SH inputs. Required for spending P2SH outputs in PSBTs.

      Parameters

      • script: Buffer

        The redeem script buffer

      Returns void

    • get witnessScript(): undefined | Buffer

      Gets the witness script for segwit inputs (P2WSH, P2SH-P2WSH). The witness script contains the actual spending conditions for segwit script outputs. For multisig segwit, this is the multisig script with the signature requirements.

      Returns undefined | Buffer

    • set witnessScript(script: Buffer): void

      Sets the witness script for segwit inputs. Required for spending P2WSH and P2SH-P2WSH outputs in PSBTs.

      Parameters

      • script: Buffer

        The witness script buffer

      Returns void

    • get witnessUtxo(): undefined | { script: Buffer; value: number }

      Gets the witness UTXO.

      Returns undefined | { script: Buffer; value: number }

    • set witnessUtxo(value: { script: Buffer; value: number }): void

      Sets the witness UTXO. Required for segwit inputs in PSBTs.

      Parameters

      • value: { script: Buffer; value: number }

        The witness UTXO

        • script: Buffer

          The scriptPubKey of the output

        • value: number

          The value of the output in satoshis

      Returns void

    Methods

    • Creates a BtcTxInputTemplate from a user-provided UTXO object.

      This function prepares the UTXO for internal PSBT construction by:

      • Mapping UTXO metadata such as amount, witness/non-witness data, scripts, derivation paths, and sequence number into the PSBT-compatible format.
      • Keeping the txid stored in its original big-endian (human-readable) form internally.
      • Only converting the txid to little-endian at the time of serialization during PSBT construction (inside toPSBT() method of BtcTransactionTemplate), as required by Bitcoin’s internal protocol format.

      Parameters

      • utxo: UTXO

        The UTXO provided by the user, where txid is expected to be in big-endian format (as commonly seen in block explorers and UIs).

      Returns BtcTxInputTemplate

      A BtcTxInputTemplate instance representing the PSBT input.

      Bitcoin internally uses little-endian format for transaction IDs during transaction serialization and signing. However, for clarity and consistency with human-readable sources (like block explorers), we retain the txid in big-endian form throughout our internal structures. The conversion to little-endian is deferred until the final serialization step (toPSBT()).

      For more information on byte order in Bitcoin, see: