Expand description
§rustywallet-mempool
Mempool.space API client for fee estimation, address info, and transaction tracking.
§Features
- Fee estimation - Get recommended fee rates for different confirmation targets
- Address info - Get balance, transaction count, and UTXOs
- Transaction tracking - Get transaction details and confirmation status
- Broadcasting - Broadcast signed transactions to the network
- Block info - Get current block height and block details
- WebSocket support - Real-time updates for blocks, fees, and addresses
- Lightning stats - Lightning Network capacity, nodes, and channels
- Mining stats - Pool hashrate distribution and difficulty adjustments
§Quick Start
use rustywallet_mempool::MempoolClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = MempoolClient::new();
// Get fee estimates
let fees = client.get_fees().await?;
println!("Next block: {} sat/vB", fees.fastest_fee);
println!("1 hour: {} sat/vB", fees.hour_fee);
println!("Economy: {} sat/vB", fees.economy_fee);
// Get address balance
let info = client.get_address("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa").await?;
println!("Balance: {} sats", info.confirmed_balance());
println!("Transactions: {}", info.tx_count());
// Get UTXOs
let utxos = client.get_utxos("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa").await?;
println!("UTXOs: {}", utxos.len());
// Get current block height
let height = client.get_block_height().await?;
println!("Block height: {}", height);
Ok(())
}§WebSocket Real-time Updates
use rustywallet_mempool::websocket::{MempoolWsClient, WsSubscription};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ws = MempoolWsClient::new();
// Configure subscriptions
let sub = WsSubscription::new()
.with_blocks()
.with_fees()
.track_address("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
ws.set_subscription(sub).await;
Ok(())
}§Lightning Network Stats
use rustywallet_mempool::MempoolClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = MempoolClient::new();
// Get Lightning Network statistics
let stats = client.get_lightning_stats().await?;
println!("Capacity: {} BTC", stats.latest.capacity_btc());
println!("Channels: {}", stats.latest.channel_count);
println!("Nodes: {}", stats.latest.node_count);
Ok(())
}§Mining Pool Stats
use rustywallet_mempool::MempoolClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = MempoolClient::new();
// Get hashrate distribution
let dist = client.get_hashrate_distribution("1w").await?;
for pool in dist.top_pools(5) {
println!("{}: {:.1}%", pool.pool.name, pool.share_percent());
}
// Get difficulty adjustment
let adj = client.get_difficulty_adjustment().await?;
println!("Next adjustment: {:.2}%", adj.difficulty_change_percent());
Ok(())
}§Networks
use rustywallet_mempool::MempoolClient;
// Mainnet (default)
let mainnet = MempoolClient::new();
// Testnet
let testnet = MempoolClient::testnet();
// Signet
let signet = MempoolClient::signet();
// Custom endpoint
let custom = MempoolClient::with_base_url("https://my-mempool.example.com/api");Re-exports§
pub use client::MempoolClient;pub use client::MAINNET_URL;pub use client::SIGNET_URL;pub use client::TESTNET_URL;pub use error::MempoolError;pub use error::Result;pub use types::AddressInfo;pub use types::BlockInfo;pub use types::ChainStats;pub use types::FeeEstimates;pub use types::MempoolStats;pub use types::Transaction;pub use types::TxStatus;pub use types::Utxo;pub use types::UtxoStatus;pub use lightning::LightningChannel;pub use lightning::LightningNode;pub use lightning::LightningNetworkStats;pub use lightning::LightningStats;pub use mining::BlockRewardStats;pub use mining::DifficultyAdjustment;pub use mining::HashrateDistribution;pub use mining::MiningPoolStats;pub use mining::PoolBlock;pub use mining::PoolInfo;pub use websocket::AddressTxEvent;pub use websocket::BlockEvent;pub use websocket::MempoolInfoEvent;pub use websocket::MempoolWsClient;pub use websocket::TxConfirmedEvent;pub use websocket::WsConnectionStatus;pub use websocket::WsEvent;pub use websocket::WsSubscription;pub use websocket::WsSubscriptionBuilder;pub use websocket::MAINNET_WS_URL;pub use websocket::TESTNET_WS_URL;pub use websocket::SIGNET_WS_URL;