A client-side Reddcoin JavaScript library for Node.js and browsers. Forked from bitcoinjs-lib v7, adapted for the Reddcoin blockchain with Proof-of-Stake velocity (PoSV) support.
Written in TypeScript, with compiled JS committed for verification.
Released under the terms of the MIT LICENSE.
If you are thinking of using the master branch of this library in production, stop. Master is not stable; it is our development branch, and only tagged releases may be classified as stable.
Don't trust. Verify.
We recommend every user of this library and the reddcoinjs ecosystem audit and verify any underlying code for its validity and suitability, including reviewing any and all of your project's dependencies.
Mistakes and bugs happen, but with your help in resolving and reporting issues, together we can produce open source software that is:
Buffer's throughout, andVisit our documentation to explore the available resources. We're continually enhancing our documentation with additional features for an enriched experience. If you need further guidance beyond what our examples offer, don't hesitate to ask for help. We're here to assist you.
You can find a Web UI that covers most of the psbt.ts, transaction.ts and p2*.ts APIs here.
If you need guidance beyond what the quick start examples offer, don't hesitate to open an issue.
R for mainnet P2PKH)Reddcoin PoSV transactions include a 4-byte nTime timestamp after nLockTime:
[nVersion: 4] [vin] [vout] [nLockTime: 4] [nTime: 4]
The nTime field is included in the transaction hash (txid) but excluded from the signing hash, matching Reddcoin Core behaviour.
npm install reddcoinjs-lib
# optionally, install a key derivation library as well
npm install ecpair bip32
import { networks, payments } from 'reddcoinjs-lib';
// Generate a Reddcoin P2PKH address from a public key
const { address } = payments.p2pkh({
pubkey: publicKeyBuffer,
network: networks.reddcoin,
});
// address starts with 'R'
import { Psbt, networks } from 'reddcoinjs-lib';
const psbt = new Psbt({ network: networks.reddcoin });
psbt.addInput({
hash: '<previous tx hash>',
index: 0,
nonWitnessUtxo: Buffer.from('<raw tx hex>', 'hex'),
});
psbt.addOutput({
address: 'R...',
value: 50000n,
});
psbt.nTime = Math.floor(Date.now() / 1000);
psbt.signInput(0, keyPair);
psbt.finalizeAllInputs();
const tx = psbt.extractTransaction();
console.log(tx.toHex());
| Network | pubKeyHash | scriptHash | WIF | Bech32 |
|---|---|---|---|---|
| Reddcoin mainnet | 0x3d (R) |
0x05 |
0xbd |
rdd |
| Reddcoin testnet | 0x6f (m/n) |
0xc4 |
0xef |
trdd |
The recommended method of using reddcoinjs-lib in your browser is through a bundler like browserify or a modern build tool:
npm install reddcoinjs-lib browserify
npx browserify --standalone reddcoin -o reddcoinjs-lib.js <<< "module.exports = require('reddcoinjs-lib');"
Type declarations are included. Normal installation should include all needed type information.
This library uses a pluggable ECC interface. You must call initEccLib() with a secp256k1 implementation before using Taproot or signing features:
import { initEccLib } from 'reddcoinjs-lib';
import * as ecc from 'tiny-secp256k1';
initEccLib(ecc);
See CONTRIBUTING.md.
npm test
npm run coverage
This library is based on bitcoinjs-lib v7.0.1. The upstream complementary libraries (BIP32, BIP39, BIP38, ecpair, etc.) are compatible.