Skip to content

Latest commit

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

txbuilder

npm versionnpm downloadslicensenode

Build and sign Bitcoin Taproot transactions.

Installation

npm install txbuilder

Usage

As a module

import{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

As 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 --help

API

buildTx(options)

Build and sign a Taproot transaction.

Options:

  • privateKey (string) - 64-char hex private key for signing
  • publicKey (string) - 64-char hex public key (x-only)
  • txid (string) - Input transaction ID
  • vout (number) - Input transaction output index (default: 0)
  • inputAmount (number) - Input amount in satoshis
  • outputs (array) - Array of {pubkey, amount} objects
  • network (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

License

MIT

About

bitcoin transaction builder

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages