CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-bitcoinjs-lib

Client-side Bitcoin JavaScript library for node.js and browsers with comprehensive Bitcoin protocol support

Overall
score

99%

Overview
Eval results
Files

task.mdevals/scenario-7/

Bitcoin Transaction Analyzer

Build a Bitcoin transaction analyzer that calculates important transaction metrics including weight and virtual size. The analyzer should parse transaction data and provide detailed size calculations that are essential for fee estimation.

Requirements

Transaction Parsing

The analyzer should be able to:

  • Parse transaction data from hexadecimal string format
  • Extract transaction inputs and outputs
  • Identify transaction type (legacy vs SegWit)

Size Calculations

The analyzer must calculate and return the following metrics:

  • Transaction weight: The weight units used for block capacity calculations (BIP 141)
  • Virtual size (vsize): The effective size in bytes used for fee calculations
  • Serialized size: The actual byte size of the transaction

Input/Output Analysis

For each transaction analyzed, provide:

  • Number of inputs
  • Number of outputs
  • Whether the transaction contains witness data

Test Cases

  • Given a legacy transaction hex string, the analyzer correctly calculates weight as 4 times the byte size @test
  • Given a SegWit transaction hex string with witness data, the analyzer correctly calculates the transaction weight @test
  • Given any transaction, the virtual size equals weight divided by 4 (rounded up) @test

Implementation

@generates

API

/**
 * Analyzes a Bitcoin transaction and returns size metrics
 *
 * @param {string} txHex - The transaction in hexadecimal format
 * @returns {object} Analysis results containing:
 *   - weight: Transaction weight in weight units
 *   - virtualSize: Virtual size in bytes (vsize)
 *   - size: Actual serialized size in bytes
 *   - inputs: Number of inputs
 *   - outputs: Number of outputs
 *   - hasWitness: Whether transaction contains witness data
 */
function analyzeTransaction(txHex) {
  // Implementation here
}

module.exports = {
  analyzeTransaction
};

Dependencies { .dependencies }

bitcoinjs-lib { .dependency }

Provides Bitcoin transaction parsing and manipulation capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-bitcoinjs-lib

tile.json