BchAddr.js: Bitcoin Cash general purpose address translation for Node.js and web browsers.
Plug & Play JavaScript library for all Bitcoin Cash address format translation needs. Easy-to-use, thoroughly tested, and feature complete.
Support for the new Bitcoin Cash address format which improves upon BIP 173, as well as the Bitpay and Legacy formats.
Test out a demo address translator powered by BchAddr.js here.
Installation
Using NPM
$ npm install --save bchaddrjs-slp
Using Bower
$ bower install --save bchaddrjs-slp
Usage
In Node.js
var bchaddr = ;
Browser
Script Tag
You may include a script tag in your HTML and the bchaddr
module will be defined globally on subsequent scripts.
... ...
Code Examples
Supported formats, networks and address types.
var Format = bchaddrFormat; // Legacy, Bitpay or Cashaddr.var Network = bchaddrNetwork; // Mainnet or Testnet.var Type = bchaddrType; // P2PKH or P2SH.
Test for address format.
var isLegacyAddress = bchaddrisLegacyAddress;var isBitpayAddress = bchaddrisBitpayAddress;var isCashAddress = bchaddrisCashAddress; // true // false // true // false // true // false
Test for address network.
var isMainnetAddress = bchaddrisMainnetAddress;var isTestnetAddress = bchaddrisTestnetAddress; // true // false // true // false
Test for address type.
var isP2PKHAddress = bchaddrisP2PKHAddress;var isP2SHAddress = bchaddrisP2SHAddress; // true // false // true // false
Detect address format.
var detectAddressFormat = bchaddrdetectAddressFormat; // Format.Cashaddr // Format.Bitpay
Detect address network.
var detectAddressNetwork = bchaddrdetectAddressNetwork; // Network.Mainnet // Network.Testnet
Detect address type.
var detectAddressType = bchaddrdetectAddressType; // Type.P2PKH // Type.P2SH
Translate address from any address format into a specific format.
var toLegacyAddress = bchaddrtoLegacyAddress;var toBitpayAddress = bchaddrtoBitpayAddress;var toCashAddress = bchaddrtoCashAddress; // 1B9UNtBfkkpgt8kVbwLN9ktE62QKnMbDzR // CScMwvXjdooDnGevHgfHjGWFi9cjk75Aaj // bitcoincash:qph5kuz78czq00e3t85ugpgd7xmer5kr7c5f6jdpwk
Documentation
Generate and Browse Locally
$ npm run docs
Online
Browse automatically generated jsdocs online.