Skip to content

A Blockchain-Agnostic Coin Selection Library in Rust

Choose a tag to compare

@NeoZ666 NeoZ666 released this 30 Jun 12:10
· 4 commits to main since this release
674854c

rust-coinselect v0.1.5 – A Blockchain-Agnostic Coin Selection Library in Rust

First Public Release | GitHub | docs.rs | crates.io

We’re thrilled to announce the first stable release of rust-coinselect, a high-performance, blockchain-agnostic UTXO selection library written in Rust. Designed for wallets and blockchain nodes, it offers production-ready algorithms with a clean, extensible API.


🚀 Key Features

Multiple Algorithms

  • Knapsack, Branch and Bound, Lowest Larger, FIFO, and Single-Random-Draw.
  • Unified API for switching between strategies to optimize for the best results.

Generic & Extensible

  • Works with any UTXO-based chain (Bitcoin, Litecoin, etc.).
  • Add custom algorithms via trait implementations.

Waste-Metric Optimization

  • Balances transaction fees and long-term wallet efficiency using a cost-based waste metric.
  • Optimizes for least change and least number of inputs

Well-Documented & Tested

  • Full API docs on docs.rs.
  • Benchmarks and unit tests for reliability.

📦 Getting Started

Add to Cargo.toml:

[dependencies]
rust-coinselect = "0.1.5"

📚 Quick Example

use rust_coinselect::{
    types::{CoinSelectionOpt, ExcessStrategy, OutputGroup},
    selectcoin::select_coin,
};

// UTXOs converted to OutputGroups
let output_groups = vec![
    OutputGroup { value: 1_000_000, weight: 100, input_count: 1, creation_sequence: None },
    OutputGroup { value: 2_000_000, weight: 100, input_count: 1, creation_sequence: None },
];

let options = CoinSelectionOpt {
    target_value: 1_500_000u64,
    target_feerate: 0.5f32,
    long_term_feerate: Some(0.3f32),
    min_absolute_fee: 1000u64,
    base_weight: 72u64,
    change_weight: 18u64,
    change_cost: 250u64,
    avg_input_weight: 300u64,
    avg_output_weight: 250u64,
    min_change_value: 1_000u64,
    excess_strategy: ExcessStrategy::ToChange,
};

if let Ok(selection_output) = select_coin(&output_groups, &options) {
    println!("Indexes of the selected utxos = {:?}", selection_output.selected_inputs);
}

👉 See bitcoin specific example given here.

👉 See more in the README or API docs.


💬 Community & Contributions

We welcome feedback, bug reports, and contributions!


🙏 Thank You!

This release is just the beginning. We’re excited to see how the community uses and improves rust-coinselect!

🔗 Links: