zeldhash-miner (Rust SDK)
Native Rust orchestrator for Zeldhash mining. This crate provides a high-level API to mine Bitcoin transactions with vanity txids (leading zero hex digits).
Learn more at https://zeldhash.com.
The crate ships with CPU + WebGPU support enabled by default. The runtime use_gpu option decides whether to attempt the GPU path, with automatic fallback to CPU if GPU initialization fails.
Installation
[]
= "0.3"
Or with specific features:
[]
= { = "0.3", = false, = ["cpu", "serde"] }
Quick Start
use ;
Features
| Feature | Default | Description |
|---|---|---|
cpu |
✓ | CPU mining path |
gpu |
✓ | WebGPU backend (runtime fallback to CPU if unavailable) |
rayon |
✓ | Parallelizes CPU batches across threads |
serde |
✓ | Serialization for options, params, results, and errors |
Feature Combinations
# Default: CPU + GPU + Rayon + Serde
# CPU-only (skip GPU dependencies, faster compile)
# CPU + Rayon (multi-threaded CPU, no GPU)
API Reference
ZeldMiner::new(options) -> Result<ZeldMiner>
Creates a new miner instance. If use_gpu is true but GPU initialization fails, the miner falls back to CPU silently.
Options:
network:NetworkOption::Mainnet | Testnet | Signet | Regtestbatch_size: Base batch size per iterationuse_gpu: Attempt GPU backendworker_threads: Thread count for CPU mining (Rayon)sats_per_vbyte: Fee rate for PSBT construction
miner.mine_transaction(params, on_progress, on_found) -> Result<MineResult>
Mines for a nonce producing the requested leading zeros and returns an unsigned PSBT.
Params:
inputs: Vec<TxInputDesc>— UTXOs to spendoutputs: Vec<TxOutputDesc>— Destinations (mark exactly one aschange: true)target_zeros: u8— Leading zero hex digits (0–32)start_nonce: Option<u64>— Starting point (default 0)batch_size: Option<u32>— Override instance batch sizedistribution: Option<Vec<u64>>— ZELD distribution values (enables CBOR nonce encoding)
Returns:
psbt: String— Base64-encoded unsigned PSBTtxid: String— Transaction ID with leading zerosnonce: u64— Winning nonceattempts: u128— Total hashes computedduration_ms: u128— Elapsed timehash_rate: f64— Hashes per second
Control Methods
miner.pause; // Pause the current mining run
miner.resume; // Resume after pause
miner.stop; // Abort and reject the mining promise
Each
ZeldMinerinstance coordinates a single mining run at a time. Create separate instances for concurrent searches.
ZELD Distribution Mode
When distribution is provided, the OP_RETURN payload becomes:
OP_RETURN | push | "ZELD" | CBOR([distribution..., nonce])
The nonce is appended as the final CBOR element. Bitcoin nodes truncate the CBOR array to match the count of spendable outputs, so the nonce is automatically ignored by downstream wallets while still affecting the txid for mining.
let params = MineParams ;
Error Handling
use ;
match miner.mine_transaction
Error Codes
| Code | Description |
|---|---|
InvalidAddress |
Address parsing failed |
UnsupportedAddressType |
Only P2WPKH and P2TR supported |
InsufficientFunds |
Inputs don't cover outputs + fees |
MultipleChangeOutputs |
More than one change output |
InvalidInput |
Bad parameter (txid, batch_size, etc.) |
WorkerError |
Internal GPU/worker failure |
MiningAborted |
Mining was stopped |
NoMatchingNonce |
Exhausted nonce range without finding match |
DustOutput |
Output below dust limit (310 sats P2WPKH / 330 sats P2TR) |
Notes:
- A change output is optional. If provided but the computed change would be below the dust limit, the change is omitted and the extra sats are counted as fees.
- You can also build transactions with no change output (e.g., sweeping a wallet).
Build & Test
# Run tests with default features
# CPU-only tests
# Check no_std compatibility of core
Notes
- GPU support is compiled by default; setting
use_gputofalsekeeps you on CPU. - When
use_gpuistrue, the miner falls back to CPU if the WebGPU context cannot be created. - The core crate (
zeldhash-miner-core) isno_stdcompatible withalloc. - Release flows are documented in docs/RELEASING.md.
License
MIT