Nimiq Utils

Production-ready JavaScript utilities for blockchain development. Battle-tested, type-safe, and tree-shakable.

Why Nimiq Utils

Built for real-world applications

Every utility has been battle-tested in production scenarios, from the official Nimiq Wallet to third-party integrations.

  • Performance First

    Optimized algorithms and minimal overhead

  • Framework Agnostic

    Works with any JS framework & SSR safe

  • Flexible & Great DX

    Intuitive APIs designed for developer productivity

  • Well‑Documented

    Comprehensive docs with examples & real‑world use cases

  • Production Used

    Powers Nimiq Wallet & other official ecosystem apps

  • Open Source

    100% open source with community contributions welcome

Quick Examples

See Nimiq Utils in action with real-world code snippets

ts
import { ValidationUtils } from '@nimiq/utils'

// Validate Nimiq address format
ValidationUtils.isValidAddress('NQ48 8CKH BA24...')
// → true

// Check if it's a user-friendly address
ValidationUtils.isUserFriendlyAddress('NQ48 8CKH BA24...')
// → true
ts
import { AddressBook } from '@nimiq/utils'

// Convert between address formats
const userFriendly = 'NQ48 8CKH BA24 Y7R5 GXM9 PQ8R HHGJ'
const hex = AddressBook.toHex(userFriendly)
// → '84c8e...'

// Convert back to user-friendly
const address = AddressBook.fromHex(hex)
// → 'NQ48 8CKH BA24 Y7R5 GXM9 PQ8R HHGJ'
ts
import { FormattableNumber } from '@nimiq/utils'

// Format NIM amounts
const amount = new FormattableNumber(1.5, 5)
amount.toString() // → "1.50000"
amount.toCurrency('NIM') // → "1.50 NIM"

// Auto-format with locale
amount.toLocaleString() // → "1.50000"
ts
import { getExchangeRates } from '@nimiq/utils'

// Get current exchange rates
const rates = await getExchangeRates(['nim'], ['usd', 'eur'])
// → { nim: { usd: 0.012, eur: 0.011 } }

// Calculate fiat value
const nimValue = 100
const usdValue = nimValue * rates.nim.usd
ts
import { posSupplyAt } from '@nimiq/utils'

// Get total supply at specific time
const supply = posSupplyAt(Date.now())
// → 3000000000 (in smallest unit)

// Get supply at block height
const supplyAtBlock = posSupplyAt(1000000)

All Modules

Browse all available utility modules by category