Caravan Documentation
    Preparing search index...

    Function createCPFPTransaction

    • Creates a Child-Pays-for-Parent (CPFP) transaction to accelerate the confirmation of an unconfirmed parent transaction.

      This function implements a simplified version of the CPFP strategy used in Bitcoin Core. It creates a new transaction (child) that spends an output from the original unconfirmed transaction (parent), including a higher fee to incentivize miners to confirm both transactions together.

      The CPFP calculation process:

      1. Analyze the parent transaction to determine its fee, size, and available outputs.
      2. Validate the provided parent UTXO matches the expected output.
      3. Create a child transaction template with the target fee rate for the combined package.
      4. Add the parent UTXO as an input to the child transaction.
      5. Iteratively add additional inputs to the child transaction until the combined fee rate of the parent and child meets or exceeds the target fee rate.
      6. Calculate and set the change output amount for the child transaction.
      7. Validate the child transaction and ensure the combined fee rate is sufficient.

      The combined fee rate is calculated as: (parentFee + childFee) / (parentVsize + childVsize)

      Parameters

      • options: CPFPOptions

        Configuration options for creating the CPFP transaction.

      Returns string

      The base64-encoded PSBT of the CPFP (child) transaction.

      If CPFP is not possible, if the transaction creation fails, or if the combined fee rate doesn't meet the target (in strict mode).

      const cpfpTx = createCPFPTransaction({
      originalTx: originalTxHex,
      availableInputs: availableUTXOs,
      spendableOutputIndex: 1,
      parentUtxo: enrichedParentUtxo,
      changeAddress: 'bc1q...',
      network: Network.MAINNET,
      dustThreshold: '546',
      scriptType: 'P2WSH',
      targetFeeRate: '15',
      absoluteFee: '1000',
      requiredSigners: 2,
      totalSigners: 3,
      strict: true
      });