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.
Reddcoin Core rejects version > 1 transactions with a zero nTime, and version 1 transactions in the PoS era. So:
new Transaction() and new Psbt() create version 2 transactions. Set nTime (normally the current time) before broadcasting.Psbt.extractTransaction() throws if nTime is still 0. Create the Psbt with { autoNTime: true } to have the current time filled in at extraction instead.nTime isn’t signed, Psbt.setNTime() also works after signing and finalizing. It changes the txid, but not the signatures.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.signInput(0, keyPair);
psbt.finalizeAllInputs();
// required before extracting; nTime isn't signed, so it can be set this late
psbt.setNTime(Math.floor(Date.now() / 1000));
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 |
| Reddcoin regtest | 0x7a (r) |
0x05 |
0xef |
rcrt |
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
The integration tests run against a Reddcoin regtest node and regtest-server in Docker:
npm run integration:up # start reddcoind (regtest) + regtest-server, wait until ready
npm run integration
npm run integration:down
On regtest, CSV, segwit and taproot are activated with -vbparams so their tests can run.
They are not active on Reddcoin mainnet: these tests exercise Reddcoin Core’s
implementation, not features available on the live network.
This library is based on bitcoinjs-lib v7.0.1. The upstream complementary libraries (BIP32, BIP39, BIP38, ecpair, etc.) are compatible.