Loading…
Satoshi/BSV/USD and multi-fiat currency conversion with exchange rate caching and wallet settings integration — convert between crypto (SATS, BSV) and 15+ fiat currencies with auto-refresh.
npm install @bsv/amountinatorimport { CurrencyConverter } from '@bsv/amountinator'
const converter = new CurrencyConverter() // 5-min auto-refresh
await converter.initialize()
// Auto-detect input currency, convert to user's preference
const formatted = await converter.convertAmount('5000')
console.log(formatted.formattedAmount) // e.g. "5,000 satoshis"
console.log(formatted.hoverText) // present for very small displayed values
// Cleanup (stop auto-refresh)
converter.dispose()convertToSatoshis() rounds up to ensure sufficient paymentThe package root provides matching typed entry points for Node.js ESM and
CommonJS consumers. The published tarball is checked with publint, strict
@arethetypeswrong/core resolution, and clean installs that import and
require both public exports. Node.js 22 or newer is supported.
const converter = new CurrencyConverter() // 5-min interval
await converter.initialize()const formatted = await converter.convertAmount('5000') // "5000" or "0.1" or "10 USD"
console.log(formatted.formattedAmount) // formatted for display
console.log(formatted.hoverText) // optional full value for tiny amountsconst usdAmount = converter.convertCurrency(0.1, 'BSV', 'USD') // 6.2 (if rate = 62)const symbol = converter.getCurrencySymbol() // "quot; if USD, "€" if EURconst sats = await converter.convertToSatoshis(10) // If preferred = 'USD', USD→SATS
console.log(sats) // e.g. 1610000 (rounded up)const staticConverter = new CurrencyConverter(0) // refreshInterval = 0
await staticConverter.initialize()
const amount = await staticConverter.convertAmount('100')
// Rates will not auto-updateconvertAmount() auto-detects if input is SATS, BSV, or fiat (via suffix)convertToSatoshis() rounds up (Math.ceil) for payment safetyconvertCurrency() throws if usdPerBsv <= 0; call initialize() firstdispose() before component unmountconvertToSatoshis() always rounds UP; use convertCurrency() for exact values