rustywallet-electrum
Electrum protocol client for Bitcoin balance checking and UTXO fetching.
Features
- Balance checking - Get confirmed and unconfirmed balance for any address
- Batch queries - Check multiple addresses efficiently in a single request
- UTXO listing - Get unspent outputs for transaction building
- Transaction operations - Get raw transactions and broadcast signed ones
- TLS support - Secure connections to Electrum servers
- Certificate pinning - Enhanced security with SSL certificate pinning
- Server discovery - DNS-based server discovery with latency testing
- Connection pooling - Efficient connection management for high throughput
- Real-time subscriptions - Address and header change notifications
- No rate limits - Unlike public APIs, Electrum has no rate limiting
Quick Start
use ;
async
Server Discovery
Find the best server automatically:
use ServerDiscovery;
let discovery = new;
let best = discovery.best_server.await?;
println!;
let client = with_config.await?;
Connection Pooling
Manage multiple connections efficiently:
use ;
let config = ssl;
let pool = new;
pool.initialize.await?;
// Acquire connection from pool
let client = pool.acquire.await?;
let balance = client.get_balance.await?;
// Connection automatically returned when dropped
Batch Requests
Efficiently query multiple addresses:
use BatchRequest;
let response = new
.balances
.utxos
.execute
.await?;
println!;
println!;
Real-time Subscriptions
Monitor addresses for changes:
use ;
let client = new.await?;
// Subscribe to address
let status = client.subscribe_address.await?;
// Subscribe to new blocks
let header = client.subscribe_headers.await?;
println!;
// Listen for events
let mut rx = client.subscribe;
while let Ok = rx.recv.await
Certificate Pinning
Enhanced security with certificate pinning:
use ;
let tls_config = new
.pin_hex?
.allow_unpinned
.build;
Address Support
All Bitcoin address types are supported:
- P2PKH (1...)
- P2SH (3...)
- P2WPKH (bc1q...)
- P2WSH (bc1q... longer)
- P2TR (bc1p...)
Custom Configuration
use ClientConfig;
use Duration;
let config = ssl
.with_port
.with_timeout
.with_retry;
let client = with_config.await?;
Public Servers
Built-in list of public Electrum servers:
electrum.blockstream.info:50002(SSL)electrum1.bluewallet.io:443(SSL)bitcoin.aranguren.org:50002(SSL)
API Reference
Balance Methods
get_balance(address)- Get balance for single addressget_balances(addresses)- Batch balance check
UTXO Methods
list_unspent(address)- List UTXOs for address
Transaction Methods
get_transaction(txid)- Get raw transactionbroadcast(raw_tx)- Broadcast signed transactionget_history(address)- Get transaction history
Server Methods
server_version()- Get server versionping()- Check connectionget_block_height()- Get current block heightestimate_fee(blocks)- Estimate fee rate
Discovery (v0.2)
ServerDiscovery::new()- Create discovery servicebest_server()- Find lowest latency serverreachable_servers()- Get all reachable servers
Pooling (v0.2)
ConnectionPool::new()- Create connection poolacquire()- Get connection from poolstats()- Get pool statistics
Subscriptions (v0.2)
subscribe_address(address)- Subscribe to address changessubscribe_headers()- Subscribe to new blockssubscribe()- Get event receiver
Batch (v0.2)
BatchRequest::new()- Create batch builderGapLimitScanner- Scan with gap limit
License
MIT