Creates an instance of TransactionAnalyzer.
Configuration options for the analyzer
Gets whether RBF is assumed to be always possible, regardless of signaling.
True if RBF is assumed to be always possible, false otherwise
Sets whether to assume RBF is always possible, regardless of signaling.
Whether to assume RBF is always possible
Gets the list of available UTXOs for potential use in fee bumping.
An array of available UTXOs
Check if Child-Pays-for-Parent (CPFP) is possible for the transaction.
True if CPFP is possible, false otherwise.
Checks if RBF (Replace-By-Fee) can be performed on this transaction.
RBF allows unconfirmed transactions to be replaced with a new version that pays a higher fee. There are two types of RBF:
This method determines if RBF is possible based on three criteria:
It uses the transaction's input templates and compares them against the available UTXOs to ensure that the wallet has control over at least one input, which is necessary for RBF.
While BIP125 defines the standard for signaled RBF, some nodes and miners may accept full RBF, allowing replacement of any unconfirmed transaction.
CAUTION: Assuming full RBF when a transaction doesn't signal it may lead to:
True if RBF can be performed (signaled or assumed), false otherwise
Calculates the total package size for a potential CPFP transaction. This includes the size of the current (parent) transaction and the estimated size of the child transaction.
The total package size in vbytes
Estimates the virtual size of a potential CPFP child transaction.
The estimated vsize of the child transaction in vbytes
Calculates and returns the fee of the transaction in satoshis.
The transaction fee in satoshis
Calculates and returns the fee rate of the transaction in satoshis per vbyte.
The transaction fee rate in satoshis per vbyte
Gets the deserialized inputs of the transaction.
An array of transaction inputs
Each input's txid will be in big-endian format, consistent with how TXIDs are typically
displayed in block explorers and user interfaces.
If you are performing any low-level Bitcoin protocol operations with these inputs (e.g. signing,
hashing, or PSBT creation), ensure that you convert the txid to little-endian byte order
as required by the Bitcoin protocol.
Calculates the minimum total fee required for a successful CPFP (Child-Pays-For-Parent) operation.
This method calculates the fee needed for a child transaction to boost the fee rate of the current (parent) transaction using the CPFP technique. It considers:
The calculation aims to determine how much additional fee the child transaction needs to contribute to bring the overall package fee rate up to the target.
Assumptions:
References:
The estimated additional CPFP fee in satoshis. This value represents how much extra fee the child transaction should include above its own minimum required fee. A positive value indicates the amount of additional fee required. A zero or negative value (rare) could indicate that the current transaction's fee is already sufficient for the desired rate.
Calculates the minimum total fee required for a valid RBF (Replace-By-Fee) replacement transaction.
This method determines the minimum fee needed to replace the current transaction using the RBF protocol, as defined in BIP 125. It considers two key factors:
Key considerations:
The calculation ensures that the new transaction meets the minimum fee increase required by the RBF rules, which is: minimum_fee = original_fee + (incremental_relay_fee * transaction_size)
References:
The minimum total fee required for the replacement transaction in satoshis. This is always at least the current fee plus the minimum required increase. * Note: This getter does not consider the user's target fee rate. It's the responsibility of the RBF function to ensure that the new transaction's fee is the maximum of this minimum fee and the fee calculated using the user's target fee rate.
Gets the deserialized outputs of the transaction.
An array of transaction outputs
Recommends the optimal fee bumping strategy based on the current transaction state.
The recommended fee bumping strategy
Gets the current target fee rate in satoshis per vbyte.
The target fee rate in satoshis per vbyte.
Gets the transaction ID (txid) of the analyzed transaction.
The transaction ID
Gets the virtual size (vsize) of the transaction in virtual bytes. Note: This uses bitcoinjs-lib's implementation which applies Math.ceil() for segwit transactions, potentially slightly overestimating the vsize. This is generally acceptable, especially for fee bumping scenarios.
The virtual size of the transaction
Gets the weight of the transaction in weight units.
The weight of the transaction
Performs a comprehensive analysis of the Bitcoin transaction.
This method aggregates various metrics and properties of the transaction, including size, fees, RBF and CPFP capabilities, and the recommended fee bumping strategy. It utilizes internal calculations and checks performed by other methods of the TransactionAnalyzer class.
A TxAnalysis object containing detailed information about the transaction.
const txAnalyzer = new TransactionAnalyzer(options);
try {
const analysis = txAnalyzer.analyze();
console.log(`Transaction ${analysis.txid} analysis:`);
console.log(`Fee rate: ${analysis.feeRate} sat/vB`);
console.log(`Can RBF: ${analysis.canRBF}`);
console.log(`Can CPFP: ${analysis.canCPFP}`);
console.log(`Recommended strategy: ${analysis.recommendedStrategy}`);
} catch (error) {
console.error('Analysis failed:', error);
}
ProtectedcanProtectedDetermines if CPFP (Child-Pays-For-Parent) can be performed on this transaction.
True if CPFP can be performed, false otherwise
ProtecteddeserializeProtectedDeserializes and formats the transaction inputs.
This method processes the raw input data from the original transaction and converts it into a more easily manageable format. It performs the following operations for each input:
ProtecteddeserializeProtectedDeserializes and formats the transaction outputs.
This method processes the raw output data from the original transaction and converts it into a more easily manageable format. It performs the following operations for each output:
Retrieves the change output of the transaction, if it exists.
The change output or null if no change output exists
Creates input templates from the transaction's inputs.
This method maps each input of the analyzed transaction to a BtcTxInputTemplate. It extracts the transaction ID (txid) and output index (vout) from each input to create the templates. Note that the amount in satoshis is not included, as this information is not available in the raw transaction data.
An array of BtcTxInputTemplate objects representing the inputs of the analyzed transaction. These templates will not have amounts set and will need to be populated later with data from an external source (e.g., bitcoind wallet, blockchain explorer, or local UTXO set).
Each input's txid will be in big-endian format, consistent with how TXIDs are typically
displayed in block explorers and user interfaces.
If you are performing any low-level Bitcoin protocol operations with these inputs (e.g. signing,
hashing, or PSBT creation), ensure that you convert the txid to little-endian byte order
as required by the Bitcoin protocol.
Creates output templates from the transaction's outputs.
This method maps each output of the analyzed transaction to a BtcTxOutputTemplate. It extracts the recipient address, determines whether it's a change output or not, and includes the amount in satoshis. The output type is set to "change" if the output is spendable (typically indicating a change output), and "destination" otherwise.
An array of BtcTxOutputTemplate objects representing the outputs of the analyzed transaction.
ProtectedisProtectedChecks if the transaction signals RBF (Replace-By-Fee).
True if the transaction signals RBF, false otherwise
ProtectedrecommendProtectedRecommends the optimal fee bumping strategy based on the current transaction state.
The recommended fee bumping strategy
TransactionAnalyzer Class
This class provides comprehensive analysis of Bitcoin transactions, including fee estimation, RBF (Replace-By-Fee) and CPFP (Child-Pays-For-Parent) capabilities. It's designed to help wallet developers make informed decisions about fee bumping strategies for unconfirmed transactions.
Key Features:
Usage: const analyzer = new TransactionAnalyzer({txHex,...other-options}); const analysis = analyzer.analyze();
Remarks
As this is a public-facing class, any input transaction IDs (
txid) returned by its methods are provided in big-endian format, consistent with how they appear in UIs and block explorers.If you are using these
txids internally for raw Bitcoin protocol operations, you may need to reverse them to little-endian using a helper such asreverseHex().For more information on byte order in Bitcoin, see:
See
https://learnmeabitcoin.com/technical/general/byte-order