npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bitpay-rates

v3.1.0

Published

A tiny Node.js wrapper for the BitPay Rates API

Readme

bitpay-rates

CI npm

A lightweight Node.js wrapper for BitPay exchange rates, written in TypeScript.

Zero runtime dependencies, promise-based, ESM (and require() on Node 22.12+). Talks to the official public Rates API (X-Accept-Version: 2.0.0).

Requirements

  • Node.js >= 22.12
npm install bitpay-rates

Breaking changes in v3

  • Promise-only. The legacy callback signature (get(code, cb)) is gone — use async/await or .then() / .catch().
  • Named arguments. get() now takes a single { base, quote } object, so there is no argument order to remember: get('USD', 'ETH') becomes get({ base: 'ETH', quote: 'USD' }).
  • get({ base }) returns the whole table for that base, which v2 could not express. get({ quote }) returns that one rate against BTC.
  • Dual ESM + CJS (the CJS file is gone in 3.1 — see below).
  • Node.js >= 22 (3.1 requires >= 22.12).
  • Requests time out after 10 seconds.
  • Currency codes are validated (/^[A-Z0-9]{2,10}$/); anything else rejects with a TypeError before a request is made.

v3.1 ships a single ESM file. require('bitpay-rates') still works on Node 22.12+ (require(esm)). Node 22.0–22.11 need import or an upgrade.

Usage

ESM / TypeScript

import { get, type RateObj } from 'bitpay-rates';

const all: RateObj[] = await get();
// GET /rates/BTC  → every rate against BTC

const vsEth: RateObj[] = await get({ base: 'ETH' });
// GET /rates/ETH  → every rate against ETH

const usd: RateObj = await get({ quote: 'USD' });
// GET /rates/BTC/USD  → { code: 'USD', name: 'US Dollar', rate: 76471.42 }

const ethUsd: RateObj = await get({ base: 'ETH', quote: 'USD' });
// GET /rates/ETH/USD

base is the cryptocurrency you are pricing (default BTC); quote is the currency you want the price in. Omitting quote gives the full table. The return type follows from that: RateObj[] without quote, RateObj with it.

The default export is a namespace object holding the same function, so the v2 import style keeps working:

import bitpayRates from 'bitpay-rates';

const usd = await bitpayRates.get({ quote: 'USD' });

CommonJS

const { get } = require('bitpay-rates');
// or: const bitpayRates = require('bitpay-rates'); bitpayRates.get({ quote: 'USD' })

get({ quote: 'USD' })
  .then((rate) => console.log(rate))
  .catch((err) => console.error(err));

All four styles — named or default, ESM or CommonJS — are asserted against the built artifact on every CI run and before every publish (npm run smoke).

Errors

get() rejects when BitPay returns a non-2xx status, an { error } payload, malformed JSON, a network failure, or when the request exceeds 10 seconds. It rejects with a TypeError — before any request — when a code is not 2-10 alphanumeric characters.

It also rejects when the response shape does not match what you asked for. GET /rates/{code} is polymorphic: a base with a rate table answers with a list, anything else answers with a single rate. So get({ base: 'USD' }) rejects rather than handing you a RateObj typed as RateObj[].

import { get } from 'bitpay-rates';

get({ quote: 'INVALID' })
  .then((rate) => console.log(rate))
  .catch((err) => console.error(err));

More examples in example/rates-example.mjs (run npm run build first).

Types

type RateObj = { code: string; name: string; rate: number };
type RateQuery = { base?: string; quote?: string };

function get(): Promise<RateObj[]>;
function get(query: { base?: string; quote?: undefined }): Promise<RateObj[]>;
function get(query: { base?: string; quote: string }): Promise<RateObj>;

Both codes are uppercased automatically and must match /^[A-Z0-9]{2,10}$/. Default base is BTC.

Available codes

See CODES.md. It is regenerated from GET /rates/BTC on every release PR (npm run update-codes). Codes containing _ (chain-specific variants such as USDC_arb) appear in that table, but BitPay rejects them as a base or quote, so they cannot be queried individually.

Security

Zero runtime dependencies, published from CI only via npm Trusted Publishing (OIDC) with a provenance attestation, and every release is gated on a human publishing the draft GitHub Release. See SECURITY.md to report a vulnerability.

Contributing

PRs only — see CONTRIBUTING.md. MIT licensed.

Related packages