Client-side Bitcoin JavaScript library for node.js and browsers with comprehensive Bitcoin protocol support
Overall
score
99%
Build a Bitcoin transaction fee validation tool that analyzes and validates fees for Partially Signed Bitcoin Transactions (PSBTs) before they are broadcast to the network.
Create a module that validates transaction fees for PSBTs to prevent accidentally overpaying fees. The validator should:
The validator should accept:
The validator should return an object containing:
fee: The absolute fee amount in satoshisfeeRate: The calculated fee rate in sat/vBisValid: Boolean indicating whether the fee rate is within acceptable limitsmaxFeeRate: The maximum fee rate threshold used for validationThe validator should handle these error cases:
Given a valid PSBT with a reasonable fee rate (under 100 sat/vB), the validator returns the correct fee, fee rate, and marks it as valid. @test
Given a valid PSBT with a high fee rate (over 100 sat/vB), the validator calculates the correct fee and fee rate, and marks it as invalid when using the default threshold. @test
Given a valid PSBT with a high fee rate that is validated with a custom maximum threshold above that rate, the validator marks it as valid. @test
Given an invalid Base64 string that is not a valid PSBT format, the validator throws an error. @test
@generates
/**
* Validates PSBT transaction fees and calculates fee rates
*
* @param {string} psbtBase64 - Base64-encoded PSBT string
* @param {number} [maxFeeRate=100] - Maximum acceptable fee rate in sat/vB
* @returns {{fee: number, feeRate: number, isValid: boolean, maxFeeRate: number}}
* @throws {Error} If PSBT is invalid or missing required data
*/
function validatePsbtFee(psbtBase64, maxFeeRate = 100) {
// IMPLEMENTATION HERE
}
module.exports = {
validatePsbtFee
};Provides PSBT parsing, fee calculation, and transaction handling functionality.
Install with Tessl CLI
npx tessl i tessl/npm-bitcoinjs-libdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10