# @psf/bch-js

> A JavaScript library for working with Bitcoin Cash and SLP Tokens

Latest version **7.1.15** (published 2026-10-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @psf/bch-js
pnpm add @psf/bch-js
yarn add @psf/bch-js
bun add @psf/bch-js
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 7.1.15 |
| Published | 2026-10-19 |
| First published | 2020-07-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 23 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Chris Troutner |
| Maintainers | psf-account, chris.troutner |

## Links

- npm: https://www.npmjs.com/package/@psf/bch-js
- Repository: https://github.com/Permissionless-Software-Foundation/bch-js
- Issues: https://github.com/Permissionless-Software-Foundation/bch-js/issues
- npm.io page: https://npm.io/package/@psf/bch-js

## Dependencies (23)

- [ini](https://npm.io/package/ini.md) 6.0.0
- [wif](https://npm.io/package/wif.md) 2.0.6
- [bigi](https://npm.io/package/bigi.md) 1.4.2
- [bs58](https://npm.io/package/bs58.md) 4.0.1
- [axios](https://npm.io/package/axios.md) 1.20.0
- [bip38](https://npm.io/package/bip38.md) 3.1.1
- [bip39](https://npm.io/package/bip39.md) 3.1.0
- [bip66](https://npm.io/package/bip66.md) 1.1.5
- [ecurve](https://npm.io/package/ecurve.md) 1.0.6
- [slp-mdm](https://npm.io/package/slp-mdm.md) 0.0.7
- [bc-bip68](https://npm.io/package/bc-bip68.md) 1.0.5
- [@psf/bip21](https://npm.io/package/@psf/bip21.md) 2.0.1
- [slp-parser](https://npm.io/package/slp-parser.md) 0.0.4
- [bip-schnorr](https://npm.io/package/bip-schnorr.md) 0.6.7
- [ecashaddrjs](https://npm.io/package/ecashaddrjs.md) 1.0.7
- [randombytes](https://npm.io/package/randombytes.md) 2.1.0
- [safe-buffer](https://npm.io/package/safe-buffer.md) 5.2.1
- [bignumber.js](https://npm.io/package/bignumber.js.md) 9.3.1
- [@psf/coininfo](https://npm.io/package/@psf/coininfo.md) 4.0.0
- [bchaddrjs-slp](https://npm.io/package/bchaddrjs-slp.md) 0.2.14
- [satoshi-bitcoin](https://npm.io/package/satoshi-bitcoin.md) 1.0.5
- [@psf/bitcoincashjs-lib](https://npm.io/package/@psf/bitcoincashjs-lib.md) 4.0.3
- [@chris.troutner/bip32-utils](https://npm.io/package/@chris.troutner/bip32-utils.md) 1.0.5

## Recent versions

- 7.1.15 (latest) — 2026-10-19
- 7.1.14 — 2026-03-12
- 7.1.13 — 2026-02-17
- 7.1.12 — 2026-02-04
- 7.1.11 — 2026-01-16
- 7.1.10 — 2026-01-15
- 7.1.9 — 2025-12-31
- 7.1.8 — 2025-12-30
- 7.1.7 — 2025-12-30
- 7.1.6 — 2025-12-29
- 7.1.5 — 2025-12-24
- 7.1.4 — 2025-12-24
- 7.1.3 — 2025-12-22
- 7.1.2 — 2025-12-21
- 7.1.1 — 2025-12-21
- … 213 more at https://npm.io/package/@psf/bch-js/versions

## README

# bch-js

[![Version](https://img.shields.io/npm/v/@psf/bch-js)](https://www.npmjs.com/package/@psf/bch-js)
[![Downloads/week](https://img.shields.io/npm/dw/@psf/bch-js)](https://npmjs.org/package/@psf/bch-js)
[![License](https://img.shields.io/npm/l/@psf/bch-js)](https://github.com/Permissionless-Software-Foundation/bch-js/blob/master/LICENSE.md)
[![js-standard-style](https://img.shields.io/badge/javascript-standard%20code%20style-green.svg?style=flat-square)](https://github.com/feross/standard) [![Join the chat at https://gitter.im/Permissionless-Software-Foundation/bch-js](https://badges.gitter.im/Permissionless-Software-Foundation/bch-js.svg)](https://gitter.im/Permissionless-Software-Foundation/bch-js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[bch-js](https://www.npmjs.com/package/@psf/bch-js) is a JavaScript npm library for creating web and mobile apps that can interact with the Bitcoin Cash (BCH) blockchain. bch-js contains a toolbox of handy tools, and an easy API for talking with [psf-bch-api REST API](https://github.com/Permissionless-Software-Foundation/psf-bch-api). [FullStack.cash](https://fullstack.cash) offers paid cloud access to psf-bch-api. You can run your own infrastructure by following documentation on [CashStack.info](https://cashstack.info).

### Quick Links

- [Code Examples](https://github.com/Permissionless-Software-Foundation/psf-js-examples) using bch-js
- [npm Library](https://www.npmjs.com/package/@psf/bch-js)
- [API Reference](https://bchjs.fullstack.cash/)
- [x402-bch.fullstack.cash](https://x402-bch.fullstack.cash) - The REST API this library talks to by default.
- [FullStack.cash](https://fullstack.cash) - cloud-based infrastructure for application developers.
- [CashStack.info](https://cashstack.info) - bch-js is part of the Cash Stack, a JavaScript framework for writing web 2 and web 3 business applications.
- [Permissionless Software Foundation](https://psfoundation.info) - The organization that maintains this library.


### Quick Notes

- Install library: `npm install @psf/bch-js`

- Instantiate the library in your code:

```javascript
import BCHJS from "@psf/bch-js"
let bchjs = new BCHJS() // Defaults to BCHN network.
```

This library is intended to be paired with
the [psf-bch-api](https://github.com/Permissionless-Software-Foundation/psf-bch-api) REST API, and the infrastructure provided by [FullStack.cash](https://fullstack.cash). The `restURL` property can be changed to work with different Bitcoin Cash networks:

- BCHN Mainnet REST API server: https://x402-bch.fullstack.cash/v7/
- Check server status: https://metrics.fullstack.cash

## Configuration

bch-js can be configured through constructor options or environment variables. Configuration options passed to the constructor take precedence over environment variables.

### Constructor Options

When instantiating BCHJS, you can pass a configuration object:

```javascript
import BCHJS from "@psf/bch-js"

const bchjs = new BCHJS({
  restURL: 'https://x402-bch.fullstack.cash/v5/',
  bearerToken: 'your-bearer-token',
  wif: 'your-private-key-wif',
  paymentAmountSats: 20000,
  bchServerURL: 'https://bch.fullstack.cash'
})
```

### Configuration Options

| Option | Type | Required | Default | Description |
|--------|------|----------|---------|-------------|
| `restURL` | string | Yes* | - | The REST API server URL for making API calls. Must include trailing slash. *Required unless `RESTURL` environment variable is set. |
| `bearerToken` | string | No | `''` | Bearer token for authentication with the REST API server. |
| `wif` | string | No | `''` | Private key in WIF format. When provided, enables automatic x402 payment handling. |
| `paymentAmountSats` | number | No | `20000` | Default amount of satoshis to send when making x402 payments. |
| `bchServerURL` | string | No | `'https://bch.fullstack.cash'` | BCH server URL used for broadcasting payment transactions to the blockchain. This is separate from `restURL` and is specifically for x402 payment processing. |

### Environment Variables

You can also configure bch-js using environment variables:

| Environment Variable | Config Option | Description |
|---------------------|---------------|-------------|
| `RESTURL` | `restURL` | REST API server URL for making API calls. |
| `BCHJSBEARERTOKEN` | `bearerToken` | Bearer token for API authentication. |
| `BCHJSWIF` | `wif` | Private key in WIF format for x402 payments. |
| `BCHJSBCHSERVERURL` | `bchServerURL` | BCH server URL for x402 payment transactions. |

### Understanding restURL vs bchServerURL

These two configuration options serve different purposes:

- **`restURL`**: The REST API server used for all regular API calls (utxo queries, transaction history, etc.). This can be any bch-api compatible server, such as `https://x402-bch.fullstack.cash/v5/` or `https://bch.fullstack.cash/v5/`.

- **`bchServerURL`**: The BCH infrastructure server used specifically for broadcasting x402 payment transactions to the blockchain. This defaults to `https://bch.fullstack.cash` and should typically remain unchanged unless you have specific infrastructure requirements.

**Example Use Case**: Most users will use `https://x402-bch.fullstack.cash/v5/` as their `restURL` to access x402-protected APIs. However, when bch-js needs to make an x402 payment, it uses the `bchServerURL` (default: `https://bch.fullstack.cash`) to broadcast the payment transaction. This ensures payment transactions are sent through a reliable BCH infrastructure endpoint.

```javascript
// Use x402-bch server for API calls, but bch.fullstack.cash for payments
const bchjs = new BCHJS({
  restURL: 'https://x402-bch.fullstack.cash/v5/',
  wif: 'your-private-key-wif'
  // bchServerURL defaults to 'https://bch.fullstack.cash'
})

// Or explicitly set both
const bchjs2 = new BCHJS({
  restURL: 'https://x402-bch.fullstack.cash/v5/',
  bchServerURL: 'https://bch.fullstack.cash',
  wif: 'your-private-key-wif'
})
```

### Web Apps

[minimal-slp-wallet](https://www.npmjs.com/package/minimal-slp-wallet) is a minimal wallet 'engine' that incorporates bch-js. It's compiled with Browserify for front end apps.

[This gist](https://gist.github.com/christroutner/6cb9d1b615f3f9363af79723157bc434) shows how to include minimal-slp-wallet into a basic web page without using a framework.

[bch-wallet-web3-spa](https://github.com/Permissionless-Software-Foundation/bch-wallet-web3-spa) is a React web app template using bch-js and minimal-slp-wallet.

## Documentation:

Full documentation for this library can be found here:

- [API Reference](https://bchjs.fullstack.cash/)

bch-js uses [APIDOC](http://apidocjs.com/) so that documentation and working code
live in the same repository. To generate the documentation:

- `npm run docs`
- Open the generated `docs/index.html` file in a web browser.

## Support

Have questions? Need help? Join our community support
[Telegram channel](https://t.me/bch_js_toolkit)

## Donate

This open source software is developed and maintained by the [Permissionless Software Foundation](https://psfoundation.cash). If this library provides value to you, please consider making a donation to support the PSF developers:

<div align="center">
<img src="./img/donation-qr.png" />
<p>bitcoincash:qqsrke9lh257tqen99dkyy2emh4uty0vky9y0z0lsr</p>
</div>

## License

[MIT](LICENSE.md)

---
_Source: https://npm.io/package/@psf/bch-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
