CashAddr.js: The new Bitcoin Cash address format for Node.js and web browsers.
JavaScript implementation for the new CashAddr address format for Bitcoin Cash.
Compliant with the original CashAddr specification which improves upon BIP 173.
Installation
Using NPM
$ npm install --save cashaddrjs
Using Bower
$ bower install --save cashaddrjs
Manually
You may also download the distribution file manually and place it within your third-party scripts directory: dist/cashaddrjs-0.1.9.min.js.
Usage
In Node.js
const cashaddr = require('cashaddrjs');
const hash = [
118, 160, 64, 83, 189,
160, 168, 139, 218, 81,
119, 184, 106, 21, 195,
178, 159, 85, 152, 115
];
const address = cashaddr.encode('bitcoincash', 'P2PKH', hash);
console.log(address);
const decoded = cashaddr.decode(address);
console.log(decoded.prefix);
console.log(decoded.type);
console.log(decoded.hash);
Browser
Script Tag
You may include a script tag in your HTML and the cashaddr
module will be defined globally on subsequent scripts.
<html>
<head>
...
<script src="https://cdn.rawgit.com/bitcoincashjs/cashaddrjs/master/dist/cashaddrjs-0.1.9.min.js"></script>
</head>
...
</html>
Documentation
Generate and Browse Locally
$ npm run docs
Online
Browse automatically generated jsdocs online.