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

@mr-zwets/bchn-api-wrapper

v1.0.3

Published

a Typescript wrapper for interacting with the Bitcoin Cash Node (BCHN) API

Downloads

1,390

Readme

BCHN-API-Wrapper

This library is a Typescript wrapper for interacting with the Bitcoin Cash Node (BCHN) RPC and REST interfaces.

Compatibility

RPC and REST interface types compatible with BCHN v29.0.0.

Features

The library is a simple wrapper for using the BCHN REST and RPC-endpoints in a type-safe way.

The library is designed to be easy to use and get started with.

The library has good documentation, automated tests and zero dependencies.

Details

The BchnRestClient uses a class with unique methods for each of the endpoints.

The BchnRpcClient uses a request function which uses generics to type arguments and responses.

The REST API is ideal for read-only access to general blockchain information such as transactions, blocks, and UTXO data. In contrast, the RPC API allows for full interaction with the Bitcoin Cash node, including managing the built-in wallet, sending transactions, performing mining operations, and issuing control commands like pruning or stopping the node. While the REST API provides 11 endpoints, the RPC API offers a much broader set of 136 commands.

Configuration

To use the RPC and REST APIs on your BCHN node, you need to enable them in your node's configuration file.

  server=1
  rest=1
  txindex=1
  rpcuser=rpcuser
  rpcpassword=rpcpassword
  rpcallowip=127.0.0.1
  rpcport=8332

To learn more about the .conf settings, see the BCHN documentation.

Note that the REST-endpoints can be made public, but the RPC-endpoints should never be made public. If you want to use the RPC-endpoints of your own node remotely, you need a secure connection using SSL/TLS to encrypt your communication and protect your credentials and data from being exposed. Additionally, ensure you have strong, unique RPC credentials (username and password) set in your node's configuration file.

Install

Install the BCHN-API-Wrapper from NPM with:

pnpm install @mr-zwets/bchn-api-wrapper

REST usage

The BchnRestClient is a wrapper over the 11 BCHN REST-endpoints. For the list of the BCHN REST-endpoints see the REST documentation.

The RestClientConfig object accepts optional parameters for logger & timeoutMs

REST example

import { BchnRestClient, RestClientConfig } from 'bchn-api-wrapper'

// Create the RestClientConfig
const clientOptions: RestClientConfig = {
  url: "http://localhost:8332",
}
// Instantiate the REST client to query your BCHN node
const restClient = new BchnRestClient(clientOptions)

// Get the latest blockhash
const chainInfo = await restClient.getChainInfo()
const latestBlockHash = chainInfo.bestblockhash
console.log(`The latest blockhash is ${latestBlockHash}`)

// Get block info with includeTxDetails flag
const fullBlockInfo = await restClient.getBlock(latestBlockHash, true)
console.log(JSON.stringify(fullBlockInfo))

RPC usage

The BchnRpcClient is a thin type-wrapper over the actual RPC endpoints, with request interfaces for each endpoint. For a complete list of all BCHN RPC-endpoints see the RPC documentation.

The RpcClientConfig object accepts optional parameters for logger, timeoutMs, retryDelayMs & maxRetries

The library does not currently support making batched RPC requests.

RPC example

import { BchnRpcClient, RpcClientConfig, GetBestBlockHash, GetBlockVerbosity1 } from 'bchn-api-wrapper'

// Create the RpcClientConfig
const clientOptions: RpcClientConfig = {
  url: "http://localhost:8332",
  rpcUser: "rpcUser",
  rpcPassword: "rpcPassword"
}
// Instantiate the RPC client to query your BCHN node
const rpcClient = new BchnRpcClient(clientOptions)

// Get the latest blockhash
const latestBlockHash = await rpcClient.request<GetBestBlockHash>("getbestblockhash")
console.log(`The latest blockhash is ${latestBlockHash}`)

// Get verbosity1 info about the latest block contents
const fullBlockInfo = await rpcClient.request<GetBlockVerbosity1>("getblock", latestBlockHash, 1)
console.log(JSON.stringify(fullBlockInfo))

Run Tests

The library has automated tests using vitest, run the testing suite with:

pnpm run test