Developer documentation
What you need to build wallets, explorers, Lightning-style contracts and tooling on BTCX. If you know Taproot, you already know most of it.
Contents
- P2MR address tool
- Constructing a P2MR output
- Building a spend
- Post-quantum signatures
- Network parameters
- RPC
- Libraries and references
P2MR address tool
Enter one leaf script for a single-leaf tree, or two leaf scripts to build a two-leaf tree. Everything runs locally in your browser using Web Crypto. The leaf defaults are the p2mr_two_leaf_same_version test vector from BIP 360; choose the bc prefix to compare the address with the BIP.
Expected root for the defaults: ab179431c28d3b68fb798957faf5497d69c883c6fb1e1cd9f81483d87bac90cc.
Constructing a P2MR output
leaf_hash = tagged_hash("TapLeaf", leaf_version || compact_size(len(script)) || script)
branch_hash = tagged_hash("TapBranch", min(a, b) || max(a, b))
root = top of the tree built from leaf and branch hashes
scriptPubKey = 0x52 0x20 || root # OP_2 OP_PUSHBYTES_32 root
address = bech32m(hrp, witver=2, root) # "z" after the separator
tagged_hash(tag, m) = SHA256(SHA256(tag) || SHA256(tag) || m)
The difference from BIP 341 is what is missing: no internal key, no tweak, no parity bit. Never create a P2MR output from a key alone, and never create a depth-zero tree, which is anyone-can-spend.
Building a spend
witness = [ <signature(s) / script inputs>,
<leaf script>,
<control block> ] # optional annex last, starting 0x50
control_block = (leaf_version | 0x01) || sibling_hash_1 || ... || sibling_hash_m
Signature hashing follows BIP 341/342 "common signature message" rules, so existing tapscript signing code needs only small changes. The control block is 1 + 32m bytes instead of 33 + 32m.
Post-quantum signatures
BTCX adds post-quantum signature verification for use inside P2MR leaves:
| Scheme | Use | Status on BTCX testnet |
|---|---|---|
| ML-DSA-87 (FIPS 204) | Default post-quantum signature; the level NSA CNSA 2.0 specifies | Being integrated |
| ML-DSA-44 (FIPS 204) | Smaller, cheaper lattice signature | Being integrated |
| LMS / XMSS (SP 800-208) | Stateful hash-based signatures, which CNSA 2.0 uses for firmware signing. Hard to use safely in wallets because state must never repeat | Research only |
| SLH-DSA-SHA2-128s (FIPS 205) | Conservative hash-based fallback that does not rely on lattices | Being integrated |
| Schnorr (BIP 340) | Classical leaves and hybrid trees | Supported, unchanged |
Each post-quantum check is charged a validation weight against the tapscript budget: 150 for ML-DSA-44, 400 for ML-DSA-87 and 1,200 for SLH-DSA (a Schnorr check is 50). Measured one-input transactions are 1,027 vB (ML-DSA-44), 1,899 vB (ML-DSA-87) and 2,065 vB (SLH-DSA-SHA2-128s).
Exact opcodes, leaf versions and signature-hash rules will be documented here alongside the node release. Until then, treat any opcode name you see on this site as illustrative.
Network parameters
| Parameter | BTCX testnet |
|---|---|
| Block production | Signet (BIP 325): SHA-256d at the signet minimum, and every block signed by one of the two seed servers' keys (1-of-2 challenge, shown as signet_challenge by getblockchaininfo) |
| P2MR witness version | 2 |
| Chain | "BTCX testnet", a signet of its own, relaunched on 4 December 2026 (the first chain was a fork of Bitcoin testnet4) |
| Address prefix (HRP) | tbtcx, so P2MR addresses start with tbtcx1z. Regtest keeps Bitcoin's bcrt so the upstream test suite runs unchanged |
| P2P port | 19777 |
| RPC port | 19776 |
| Binaries | Bitcoin Core's names: bitcoind, bitcoin-cli, bitcoin-wallet, bitcoin-tx, bitcoin-util, bitcoin-qt |
| Chain flag / name | -btcxtest / btcxtest (data dir ~/.bitcoin/btcxtest) |
| Network magic | f3 b7 58 d2 |
| Genesis block | 000003238ff124028657e0fe29fb5b1d5bcc151601b50b54ece72b8b774cade5; P2MR and the post-quantum leaf are active from block 1 |
| Post-quantum key in a script | One algorithm ID byte, then the key: 01 ML-DSA-44, 02 ML-DSA-87 (default), 03 SLH-DSA-SHA2-128s. Unknown IDs are reserved for soft forks |
| P2MR scriptPubKey type | witness_v2_p2mr |
| Mainnet | Not launched |
RPC
The JSON-RPC interface is Bitcoin Core's, with these additions for P2MR. Run bitcoin-cli -btcxtest help <command> for arguments. Every change to Bitcoin Core is in five patches against v32.1, one per area, with the consensus change on its own.
pqkeygen # generate a post-quantum key pair (ML-DSA / SLH-DSA)
createp2mraddress # build a P2MR address from one or more leaf keys
signp2mrtransaction # sign P2MR inputs of a raw transaction
p2mrupdatepsbt # PSBT: record the leaf each P2MR input spends
p2mrsignpsbt # PSBT: sign P2MR inputs, also on an offline node
p2mrfinalizepsbt # PSBT: build the P2MR witnesses and the final transaction
decodescript 5220<root> # scriptPubKey type "witness_v2_p2mr"
Libraries and references
- Wallet and pool integrations: BTCX patches for Electrum, Sparrow, BDK, ckpool and others, the wallet profile they share and its test vectors.
- BIP 360 specification, with Python reference code and test vectors.
- libbitcoinpqc bindings (Rust and JavaScript examples moved out of the BIP repository).
- bitcoinpqc Rust crate for Bitcoin-oriented post-quantum signatures.
- NIST FIPS 204 (ML-DSA) and FIPS 205 (SLH-DSA).
- Building the BTCX node from source (docs/btcx-node.md).
- The source of the P2MR tool on this page, MIT-licensed and tested against the BIP 360 vectors.