Transaction Building Best Pratices
Recommendations
TransactionFactory
UTXO Management
Always track and reuse the nextUTXOs returned by each transaction method. These are your change outputs and represent your available balance for subsequent transactions.
let availableUtxos = await fetchUTXOs(address);
const result1 = await factory.createBTCTransfer({ utxos: availableUtxos, ... });
availableUtxos = result1.nextUTXOs; // Update for next transaction
const result2 = await factory.signInteraction({ utxos: availableUtxos, ... });
availableUtxos = result2.nextUTXOs; // Update againFee Rate Selection
Use realistic fee rates from mempool data. The factory uses the fee rate for vSize-based fee calculation. Setting the fee too low risks the transaction not confirming; setting it too high wastes satoshis.
Save compiledTargetScript
For deployment and interaction transactions, always save the compiledTargetScript from the response. If the second transaction fails to confirm (e.g., due to network congestion), you will need this script to cancel and recover funds.
Debug Mode
Enable debug logging to trace the iterative fee estimation process:
const factory = new TransactionFactory();
factory.debug = true;
// Console will show iteration logs:
// "Interaction Iteration 1: Previous=2000, New=3456"
// "Interaction Iteration 2: Previous=3456, New=3456"