Your private key lets the wallet sign a spend. The corresponding public key lets other software verify the signature. Generate the private key as a secret 32-byte number in the valid secp256k1 range using a cryptographically secure random source.
Derive a receiving address
- Derive the compressed 33-byte secp256k1 public key from the private key.
- Apply SHA-256 and then RIPEMD-160 to the public key. The resulting 20 bytes are its
HASH160. - Encode the hash as a P2PKH CashAddr using the
bitcoincash:prefix for mainnet. A sender decodes that address and places the hash in the new UTXO’s locking script.
This public example key derives the address for the 100,000-sat UTXO. Use it only in the exercise. Libauth P2PKH address API
Derive a P2PKH address with Libauth
import {
binToHex, hash160, hexToBin, privateKeyToP2pkhCashAddress, secp256k1
} from '@bitauth/libauth';
const privateKey = hexToBin(
'c1570ff31db1dec06a5dcacbba72735156bd42acf78fefc6717d174d842acc04'
);
const publicKey = secp256k1.derivePublicKeyCompressed(privateKey);
if (typeof publicKey === 'string') throw new Error(publicKey);
const { address } = privateKeyToP2pkhCashAddress({ privateKey, prefix: 'bitcoincash' });
console.log(binToHex(hash160(publicKey))); // b2557abfebaf263824b75ec473fd7b3db74957ea
console.log(address); // bitcoincash:qze9274lawhjvwpyka0vgula0v7mwj2hageduvrmrl
Try deriving the address in the walkthrough.
Derive many addresses from one backup
A hierarchical deterministic (HD) wallet can derive many keys from one seed. BIP32 adds a chain code to each key to derive its children. A derivation path identifies a branch or key in that tree. If your wallet uses BIP39, restore the same mnemonic and passphrase to reproduce the seed, then follow the original derivation paths to recover the keys.
Follow the receiving branch when you hand out an address and the change branch when a payment sends leftover sats back to your wallet.
- First receiving key:
m/44'/145'/0'/0/0 - First change key:
m/44'/145'/0'/1/0
These BIP44 paths use branch 0 for receiving and 1 for change. The last number selects an address within that branch. Apostrophes mark hardened steps, which require the parent private key.
BIP32 · BIP39 · BIP44 · Registered coin types
Import and export wallet keys
WIF moves one private key between wallets. To move or monitor a whole branch of an HD wallet, export an extended key, which bundles a key with the chain code used to derive its children.
- Wallet Import Format (WIF) encodes one private key and its network and compression conventions for import into a compatible wallet. Keep it private. Anyone with the WIF can sign for that key. Libauth WIF decoding
xprvexports an extended private key, which can derive child signing keys below that node. Keep it private like the seed.xpubexports an extended public key. A watch-only wallet can derive the account’s non-hardened receiving and change addresses from it. Anyone with the xpub can link those addresses. Share it only with services that need to watch them. BIP32 extended key formats
Mainnet addresses and network selection
Bitcoin Cash mainnet uses bitcoincash: addresses. Configure your wallet’s node or index to read and broadcast on the mainnet chain.
Keep the full prefix when passing an address to a wallet or library. It participates in the checksum. Decode the address and verify its prefix before building the output. An address can also tell the sender that a wallet accepts CashTokens. This changes the address type while preserving the same spending script. CashAddr specification
Run the examples on Mocknet or Chipnet
Mocknet uses the mainnet address encoding with an isolated browser chain and its own UTXOs. Chipnet is a separate live BCH test chain. It uses bchtest:, a prefix shared by several BCH test networks.
For Chipnet, open the lab in Chipnet mode or configure your client to use wss://chipnet.bch.ninja:50004. For testnet3, testnet4, or another public test chain, select its own node or Electrum endpoint. Verify the server's network and a known header after the networks diverge when they share earlier history. BCHN test network parameters · Connect to Electrum
Payment and identity formats
A receiving address is enough for the example payment. These formats cover reusable payment destinations, names, and sign-in.
- CashCode is a shareable reusable payment code. A compatible sender derives a fresh payment destination and the recipient scans for payments it can spend. Reusable Payment Addresses specification
- Cash Account is a human-readable name that resolves to payment information through an on-chain registration. Cash Accounts specification
- Nostr keys sign Nostr events. NIP-19 encodes the public key as
npuband the private key asnsec. Use a separate Nostr key for identity and keepnsecprivate. NIP-19
Continue to wallet sync to find UTXOs paid to your receiving and change addresses.
A secret cryptographic value used to sign and derive the corresponding public key.Software or a device that manages addresses and tracks UTXOs, with signing wallets also holding private keys to authorize payments.A cryptographic value derived from a private key and used to verify its signatures.A value made with a private key that lets someone with the corresponding public key verify authorization of the signed data.The elliptic curve Bitcoin Cash uses for public keys and transaction signatures.Random output designed to be infeasible to predict, used to make wallet keys and backup entropy.A 33-byte secp256k1 public key encoding that stores the x-coordinate and a prefix indicating y-coordinate parity.A 256-bit cryptographic hash function used in Bitcoin Cash transaction IDs, block hashes, and HASH160.A 160-bit hash function that Bitcoin Cash applies after SHA-256 when computing HASH160.SHA-256 followed by RIPEMD-160, producing the 20-byte public-key hash used by P2PKH.A fixed-length digest used to identify data or commit to its contents, such as a transaction ID or public-key hash.A spending condition that checks a public key against a saved hash and verifies a signature made with the corresponding private key.The Bitcoin Cash address encoding, which uses a prefix, type, payload, and checksum to describe how to construct a locking script.The public Bitcoin Cash blockchain on which payments use BCH.A shareable identifier a wallet decodes into a payment’s locking script, usually in CashAddr format on BCH.The basic unit of spendable value on Bitcoin Cash, holding satoshis and any attached tokens under the spending rules defined by its locking bytecode.The program in an output that specifies the conditions required to spend it.The smallest unit of BCH, equal to 0.00000001 BCH.A wallet that derives a tree of keys from one seed, with separate branches for receiving and change addresses.The starting secret from which an HD wallet derives its key tree, which BIP39 can derive from a mnemonic and passphrase.The standard for deriving a tree of keys from a seed and encoding the extended public and private keys.A 32-byte BIP32 value stored in an extended key and used alongside the key to derive children.A sequence of child indices identifying a key or branch in a hierarchical deterministic wallet.A standard for representing wallet entropy as a mnemonic and deriving a seed from the words and an optional passphrase.A sequence of words encoding wallet backup entropy that BIP39 combines with an optional passphrase to derive a seed.An optional BIP39 input that changes the wallet seed derived from a mnemonic.The part of an HD wallet’s key tree used for addresses that receive its own change.A convention for organizing derived keys by coin, account, receiving or change branch, and address index.A secret Base58Check export of one private key that carries its network and compression settings.A BIP32 public or private key bundled with a chain code and derivation metadata so a wallet can derive child keys.An encoded extended private key whose private key and chain code can derive descendant signing keys.An encoded extended public key that lets a watch-only wallet derive non-hardened public keys and link their addresses.A value derived from data to help detect errors, such as a mistyped CashAddr.BCH Ninja’s isolated browser chain for building and inspecting transactions using its own keys and UTXOs.A public Bitcoin Cash test chain that uses test coins and bchtest: addresses to exercise upgrades and applications.The currency unit of Bitcoin Cash, equal to 100,000,000 satoshis.The protocol wallets use to query Fulcrum for script history, UTXOs, and headers, subscribe to updates, and submit transactions.A reusable payment code that lets a compatible sender derive a fresh destination the recipient can recognize and spend.A human-readable name registered on-chain that a compatible wallet can resolve to payment information.The bytecode supplied by an input to satisfy the locking conditions of the UTXO it spends.