btctx
v0.1.0
Published
Build and sign Bitcoin Taproot transactions
Downloads
8
Maintainers
Readme
txbuilder
Build and sign Bitcoin Taproot transactions.
Installation
npm install txbuilderUsage
As a module
import { buildTx } from 'txbuilder';
const result = await buildTx({
privateKey: '0123456789abcdef...', // 64-char hex
publicKey: 'fedcba9876543210...', // 64-char hex (x-only)
txid: 'abc123...', // Input txid
vout: 0, // Input index
inputAmount: 100000, // Input satoshis
outputs: [
{ pubkey: 'dest123...', amount: 99000 }
]
});
console.log(result.hex); // Raw transaction hex
console.log(result.txid); // Transaction ID
console.log(result.address); // Sender's Taproot addressAs CLI
# 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 --helpAPI
buildTx(options)
Build 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}>
getPublicKey(privateKey)
Derive x-only public key from private key.
getAddress(publicKey, network?)
Generate Taproot (P2TR) address from public key.
Dependencies
- @cmdcode/tapscript - Taproot transaction library
License
MIT
