# Bitcoin Fee Calculator

[![Node Version](https://img.shields.io/badge/node-%3E%3D22.14.0-brightgreen)](https://nodejs.org/)

A TypeScript library for accurately calculating Bitcoin transaction sizes, virtual bytes (vBytes), and fees for various script types including SegWit and Taproot.

## Features

- Calculate transaction sizes in both vBytes and raw bytes
- Support for all standard script types:
  - Legacy (P2PKH, P2SH)
  - SegWit (P2WPKH, P2WSH)
  - Taproot (P2TR)
  - Nested SegWit (P2SH-P2WPKH, P2SH-P2WSH)
- OP_RETURN data size calculation
- Fee estimation based on sat/vByte
- Inscription transaction fee calculation

## Supported Script Types

| Type          | Description                   |
| ------------- | ----------------------------- |
| `P2PKH`       | Legacy Pay-to-Public-Key-Hash |
| `P2SH`        | Pay-to-Script-Hash            |
| `P2WPKH`      | Native SegWit                 |
| `P2WSH`       | SegWit Script                 |
| `P2TR`        | Taproot                       |
| `P2SH-P2WPKH` | Nested SegWit in P2SH         |
| `P2SH-P2WSH`  | Nested SegWit Script in P2SH  |

## Development

1. Clone the repository:

   ```bash
   git clone https://github.com/ordinalsbot/bitcoin-fee-estimator.git
   cd bitcoin-fee-estimator
   ```

2. **Optional - Using nvm:**

   ```bash
   nvm install  # Uses version from .nvmrc
   nvm use      # Switches to correct Node version
   ```

3. Install dependencies:

   ```bash
   npm install
   ```

4. Run tests:

   ```bash
   npm test
   ```

5. Build the project:
   ```bash
   npm run build
   ```
