Build and sign Bitcoin Taproot transactions.
npm install txbuilderimport{buildTx}from'txbuilder';constresult=awaitbuildTx({privateKey: '0123456789abcdef...',// 64-char hexpublicKey: 'fedcba9876543210...',// 64-char hex (x-only)txid: 'abc123...',// Input txidvout: 0,// Input indexinputAmount: 100000,// Input satoshisoutputs: [{pubkey: 'dest123...',amount: 99000}]});console.log(result.hex);// Raw transaction hexconsole.log(result.txid);// Transaction IDconsole.log(result.address);// Sender's Taproot address# Single output
txbuilder <privateKey><publicKey><txid><vout><inputAmount><destPubkey><destAmount># Multiple outputs
txbuilder <privkey><pubkey><txid> 0 100000 <dest1> 49000 <dest2> 49000
# Show help
txbuilder --helpBuild and sign a Taproot transaction.
Options:
privateKey(string) - 64-char hex private key for signingpublicKey(string) - 64-char hex public key (x-only)txid(string) - Input transaction IDvout(number) - Input transaction output index (default: 0)inputAmount(number) - Input amount in satoshisoutputs(array) - Array of{pubkey, amount}objectsnetwork(string) - Network: mainnet, testnet, regtest (default: mainnet)verify(boolean) - Verify signature after signing (default: true)
Returns:Promise<{hex, txid, address, txdata}>
Derive x-only public key from private key.
Generate Taproot (P2TR) address from public key.
- @cmdcode/tapscript - Taproot transaction library
MIT