rustywallet-tx
Bitcoin transaction building, signing, and serialization.
Features
- Transaction Building - Create transactions with multiple inputs/outputs
- Coin Selection - Automatic UTXO selection (largest-first algorithm)
- Fee Calculation - vsize-based fee estimation with dust detection
- Script Building - P2PKH, P2WPKH, and P2TR scriptPubKey generation
- Signing - Sign P2PKH and P2WPKH inputs
- Serialization - Serialize transactions to hex for broadcasting
Installation
[]
= "0.1"
Quick Start
use *;
// Create UTXOs
let utxo = Utxo ;
// Build unsigned transaction
let unsigned = new
.add_input
.add_output
.set_fee_rate // 10 sat/vB
.set_change_address
.build
.unwrap;
println!;
Signing Transactions
use ;
use PrivateKey;
let private_key = random;
let mut tx = unsigned.tx;
// Sign P2PKH input
sign_p2pkh.unwrap;
// Or sign P2WPKH input (SegWit)
sign_p2wpkh.unwrap;
// Serialize for broadcast
let hex = tx.to_hex;
Coin Selection
use ;
let utxos = vec!;
let target = 50_000; // sats
let fee_rate = 10; // sat/vB
let = select_coins.unwrap;
Fee Estimation
use ;
// Estimate fee for 2 inputs, 2 outputs at 10 sat/vB
let fee = estimate_fee;
// Check if output is dust
let is_too_small = is_dust; // true = SegWit
Script Building
use ;
let pubkey_hash = ;
let p2pkh = build_p2pkh_script;
let p2wpkh = build_p2wpkh_script;
let x_only_pubkey = ;
let p2tr = build_p2tr_script;
License
MIT