https://github.com/ealmansi/cashaddrjs
CashAddr.js: The new Bitcoin Cash address format for Node.js and web browsers.
https://github.com/ealmansi/cashaddrjs
address bitcoin browser cash cashaddr format node
Last synced: 19 days ago
JSON representation
CashAddr.js: The new Bitcoin Cash address format for Node.js and web browsers.
- Host: GitHub
- URL: https://github.com/ealmansi/cashaddrjs
- Owner: ealmansi
- License: mit
- Created: 2018-01-01T04:44:26.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-26T14:47:16.000Z (over 2 years ago)
- Last Synced: 2025-06-12T20:24:58.844Z (11 months ago)
- Topics: address, bitcoin, browser, cash, cashaddr, format, node
- Language: JavaScript
- Homepage: https://emilio.almansi.me/cashaddrjs/module-cashaddr.html
- Size: 1.46 MB
- Stars: 37
- Watchers: 4
- Forks: 28
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CashAddr.js: The new Bitcoin Cash address format for Node.js and web browsers.
[](https://travis-ci.org/ealmansi/cashaddrjs) [](https://coveralls.io/github/ealmansi/cashaddrjs?branch=master)
[](https://nodei.co/npm/cashaddrjs/)
JavaScript implementation for the new CashAddr address format for Bitcoin Cash.
Compliant with the original CashAddr [specification](https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md) which improves upon [BIP 173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki).
*Note:* This is a JavaScript implementation of the CashAddr format specification. If you are looking for a general purpose Bitcoin Cash address translation library, check out the easy-to-use and well-tested [BchAddr.js](https://github.com/ealmansi/bchaddrjs).
## Installation
### Using NPM
```bsh
$ npm install --save cashaddrjs
```
### Using Bower
```bsh
$ 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.4.4.min.js](https://unpkg.com/cashaddrjs@0.4.4/dist/cashaddrjs-0.4.4.min.js).
## Usage
### In Node.js
```javascript
const cashaddr = require('cashaddrjs');
const address = 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a';
const { prefix, type, hash } = cashaddr.decode(address);
console.log(prefix); // 'bitcoincash'
console.log(type); // 'P2PKH'
console.log(hash); // Uint8Array [ 118, 160, ..., 115 ]
console.log(cashaddr.encode(prefix, type, hash)); // 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a'
```
*Note:* This is a JavaScript implementation of the CashAddr format specification. If you are looking for an easy-to-use and well-tested library to translate between different formats, check out [BchAddr.js](https://github.com/ealmansi/bchaddrjs).
### Browser
#### Script Tag
You may include a script tag in your HTML and the `cashaddr` module will be defined globally on subsequent scripts.
```html
...
...
```
## Documentation
### Generate and Browse Locally
```bsh
$ npm run docs
```
### Online
Browse automatically generated jsdocs [online](https://emilio.almansi.me/cashaddrjs/module-cashaddr.html).