Bitcoin UI core
bitcoin-ui/bitcoin-coreFreeUtility
Types, exact formatting utilities, class helpers, and shared component styles.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/dennisonbertram/bitcoin-ui/main/public/r/bitcoin-core.jsonSource
1export type BitcoinNetwork = "mainnet" | "testnet" | "signet" | "regtest";23export type ScriptType =4 | "p2pkh"5 | "p2sh"6 | "p2wpkh"7 | "p2wsh"8 | "p2tr"9 | "op-return"10 | "unknown";1112export type TransactionState =13 | "confirmed"14 | "pending"15 | "replaced"16 | "conflicted";1718export type AmountUnit = "sat" | "btc" | "auto";1920export type BitcoinSearchKind =21 | "block-height"22 | "hash"23 | "address"24 | "unknown";2526export type SatoshiValue = bigint | number | string;2728export interface BitcoinBlock {29 height: number;30 hash: string;31 timestamp: number | Date;32 transactionCount: number;33 size: number;34 weight: number;35 miner?: string;36 feeTotal?: SatoshiValue;37}3839export interface BitcoinTransaction {40 txid: string;41 value: SatoshiValue;42 fee: SatoshiValue;43 vsize: number;44 timestamp?: number | Date;45 confirmations?: number;46 state: TransactionState;47}4849export interface BitcoinUtxo {50 txid: string;51 vout: number;52 value: SatoshiValue;53 confirmations: number;54 scriptType: ScriptType;55 address?: string;56 spendable?: boolean;57}5859export interface TransactionEndpoint {60 id: string;61 address?: string;62 label?: string;63 value: SatoshiValue;64 scriptType?: ScriptType;65 coinbase?: boolean;66}6768export interface FeeEstimate {69 label: string;70 blocks: number;71 satPerVbyte: number;72 minutes?: number;73}7475const SATOSHIS_PER_BTC = BigInt(100_000_000);7677export function toSatoshis(value: SatoshiValue): bigint {78 if (typeof value === "bigint") return value;7980 if (typeof value === "number") {81 if (!Number.isFinite(value)) {82 throw new TypeError("Satoshi value must be finite.");83 }84 return BigInt(Math.trunc(value));85 }8687 if (!/^-?\d+$/.test(value.trim())) {88 throw new TypeError("Satoshi value must be an integer string.");89 }9091 return BigInt(value);92}9394export function formatSats(95 value: SatoshiValue,96 options: Intl.NumberFormatOptions = {},97) {98 const sats = toSatoshis(value);99 return new Intl.NumberFormat("en-US", {100 maximumFractionDigits: 0,101 ...options,102 }).format(sats);103}104105export function formatBtc(106 value: SatoshiValue,107 {108 minimumFractionDigits = 0,109 maximumFractionDigits = 8,110 }: {111 minimumFractionDigits?: number;112 maximumFractionDigits?: number;113 } = {},114) {115 const sats = toSatoshis(value);116 const negative = sats < BigInt(0);117 const absolute = negative ? -sats : sats;118 const whole = absolute / SATOSHIS_PER_BTC;119 const remainder = absolute % SATOSHIS_PER_BTC;120// … truncated
What it pulls in
npm packages
