https://github.com/coinspace/cashaddr
Bitcoin Cash CashAddr
https://github.com/coinspace/cashaddr
Last synced: 9 months ago
JSON representation
Bitcoin Cash CashAddr
- Host: GitHub
- URL: https://github.com/coinspace/cashaddr
- Owner: CoinSpace
- License: mit
- Created: 2023-12-16T01:52:23.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-08-28T07:46:02.000Z (9 months ago)
- Last Synced: 2025-08-28T13:45:06.823Z (9 months ago)
- Language: JavaScript
- Size: 120 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cashaddr
This is a JavaScript implementation for the [CashAddr address](https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md) format used in Bitcoin Cash. It serves as a glue to integrate the [@scure/btc-signer](https://github.com/paulmillr/scure-btc-signer) library with Bitcoin Cash.
This library depends on and is heavily coupled with the [@scure/base](https://github.com/paulmillr/scure-base) and [@scure/btc-signer](https://github.com/paulmillr/scure-btc-signer) libraries.
## Installation
```bash
npm install cashaddr
```
## Usage
```js
import { Address, NETWORK } from 'cashaddr';
import { hex } from '@scure/base';
const hash = hex.decode('f5bf48b397dae70be82b3cca4793f8eb2b6cdac9');
const address = Address(NETWORK).encode({
format: 'cashaddr',
type: 'pkh',
hash,
});
console.log(address);
// bitcoincash:qr6m7j9njldwwzlg9v7v53unlr4jkmx6eylep8ekg2
const decoded = Address(NETWORK).decode('bitcoincash:qr6m7j9njldwwzlg9v7v53unlr4jkmx6eylep8ekg2');
console.log(decoded);
// { type: 'pkh', hash: Uint8Array(20) [...], format: 'cashaddr' }
const legacy = Address(NETWORK).encode({
format: 'legacy',
type: 'pkh',
hash,
});
console.log(legacy);
// 1PQPheJQSauxRPTxzNMUco1XmoCyPoEJCp
const converted = Address(NETWORK).toCashAddress('1PQPheJQSauxRPTxzNMUco1XmoCyPoEJCp');
console.log(converted);
// bitcoincash:qr6m7j9njldwwzlg9v7v53unlr4jkmx6eylep8ekg2
```
## License
MIT