/** * mempool.space API client for Bitcoin UTXO and fee data * * Public API endpoints (no authentication required): * - Mainnet: https://mempool.space/api * - Testnet: https://mempool.space/testnet/api * * Documentation: https://mempool.space/docs/api */ import type { Network } from "../config/networks.js"; /** * UTXO (Unspent Transaction Output) from mempool.space API */ export interface UTXO { /** * Transaction ID containing this UTXO */ txid: string; /** * Output index within the transaction */ vout: number; /** * UTXO status (confirmed or unconfirmed) */ status: { confirmed: boolean; block_height?: number; block_hash?: string; block_time?: number; }; /** * Value in satoshis */ value: number; } /** * Fee estimates from mempool.space API (sat/vB) */ export interface FeeEstimates { /** * Fee rate for fastest confirmation (~10 min) */ fastestFee: number; /** * Fee rate for fast confirmation (~30 min) */ halfHourFee: number; /** * Fee rate for standard confirmation (~1 hour) */ hourFee: number; /** * Fee rate for economy confirmation (~24 hours) */ economyFee: number; /** * Minimum relay fee rate */ minimumFee: number; } /** * Bitcoin transaction from mempool.space API */ export interface MempoolTx { txid: string; version: number; locktime: number; size: number; weight: number; fee: number; vin: Array<{ txid: string; vout: number; prevout?: { value: number; scriptpubkey_address?: string; }; sequence: number; is_coinbase: boolean; }>; vout: Array<{ value: number; scriptpubkey_address?: string; scriptpubkey_type: string; }>; status: { confirmed: boolean; block_height?: number; block_hash?: string; block_time?: number; }; } /** * Mempool statistics from mempool.space API */ export interface MempoolStats { count: number; vsize: number; total_fee: number; fee_histogram: Array<[number, number]>; } /** * Simplified fee tiers for user selection */ export interface FeeTiers { /** * Fast: ~10 minute confirmation */ fast: number; /** * Medium: ~30 minute confirmation */ medium: number; /** * Slow: ~1 hour confirmation */ slow: number; } /** * Get the mempool.space API base URL for a network */ export declare function getMempoolApiUrl(network: Network): string; /** * Get the mempool.space explorer URL for a network */ export declare function getMempoolExplorerUrl(network: Network): string; /** * Get transaction explorer URL */ export declare function getMempoolTxUrl(txid: string, network: Network): string; /** * Get address explorer URL */ export declare function getMempoolAddressUrl(address: string, network: Network): string; /** * mempool.space API client */ export declare class MempoolApi { private readonly baseUrl; private readonly network; constructor(network: Network); /** * Get UTXOs for a Bitcoin address * * @param address - Bitcoin address (bc1... for mainnet, tb1... for testnet) * @returns Array of UTXOs with txid, vout, value, and confirmation status * @throws Error if API request fails * * @example * ```typescript * const api = new MempoolApi('mainnet'); * const utxos = await api.getUtxos('bc1q...'); * const total = utxos.reduce((sum, u) => sum + u.value, 0); * ``` */ getUtxos(address: string): Promise; /** * Get current recommended fee estimates * * @returns Fee estimates in sat/vB for different confirmation targets * @throws Error if API request fails * * @example * ```typescript * const api = new MempoolApi('mainnet'); * const fees = await api.getFeeEstimates(); * console.log(`Fast fee: ${fees.fastestFee} sat/vB`); * ``` */ getFeeEstimates(): Promise; /** * Get simplified fee tiers for user selection * * Maps mempool.space fee estimates to fast/medium/slow tiers: * - Fast: fastestFee (~10 min) * - Medium: halfHourFee (~30 min) * - Slow: hourFee (~1 hour) * * @returns Fee tiers in sat/vB * @throws Error if API request fails */ getFeeTiers(): Promise; /** * Get balance for a Bitcoin address (sum of UTXOs) * * @param address - Bitcoin address * @returns Balance in satoshis * @throws Error if API request fails */ getBalance(address: string): Promise; /** * Get confirmed balance for a Bitcoin address * * @param address - Bitcoin address * @returns Confirmed balance in satoshis (excludes unconfirmed UTXOs) * @throws Error if API request fails */ getConfirmedBalance(address: string): Promise; /** * Broadcast a signed transaction to the Bitcoin network * * @param txHex - Signed transaction as hex string * @returns Transaction ID (txid) * @throws Error if broadcast fails * * @example * ```typescript * const api = new MempoolApi('mainnet'); * const txid = await api.broadcastTransaction(signedTxHex); * console.log(`Broadcast: ${getMempoolTxUrl(txid, 'mainnet')}`); * ``` */ broadcastTransaction(txHex: string): Promise; /** * Get raw transaction hex by txid * * @param txid - Transaction ID * @returns Transaction as hex string * @throws Error if API request fails * * @example * ```typescript * const api = new MempoolApi('mainnet'); * const txHex = await api.getTxHex('abc123...'); * ``` */ getTxHex(txid: string): Promise; /** * Get transaction details by txid * * @param txid - Bitcoin transaction ID (64 hex chars) * @returns Transaction details including inputs, outputs, and confirmation status * @throws Error if API request fails */ getTx(txid: string): Promise; /** * Get confirmed transaction history for a Bitcoin address (up to 25 most recent) * * @param address - Bitcoin address * @returns Array of transactions (most recent first) * @throws Error if API request fails */ getAddressTxs(address: string): Promise; /** * Get current mempool statistics * * @returns Mempool stats including transaction count, vsize, total fee, and fee histogram * @throws Error if API request fails */ getMempoolStats(): Promise; /** * Get the network this client is configured for */ getNetwork(): Network; } /** * Create a mempool.space API client for the given network */ export declare function createMempoolApi(network: Network): MempoolApi; export interface BitcoinProvider { getUtxos(address: string): Promise; getFeeEstimates(): Promise; getBalance(address: string): Promise<{ confirmed: number; unconfirmed: number; total: number; }>; broadcastTransaction(hex: string): Promise; getSource(): "bitcoin-core" | "mempool.space"; } /** * Returns the best available Bitcoin provider. * Uses Bitcoin Core if BTC_CORE_PASSWORD is set, otherwise mempool.space. */ export declare function getBitcoinProvider(network: Network): BitcoinProvider; //# sourceMappingURL=mempool-api.d.ts.map