A Rust library for verifying and monitoring cryptocurrency payments on Ethereum using the Etherscan API.
- ✅ Etherscan API Integration - Complete API coverage for accounts, transactions, tokens, and gas
- 💰 Payment Verification - Verify ETH and ERC20 token payments with confirmation tracking
- 👀 Payment Monitoring - Real-time monitoring with customizable callbacks
- ⚡ Rate Limiting - Built-in token bucket rate limiter (5 req/s default)
- 💾 Caching - In-memory LRU cache with configurable TTL
- 🔄 API Key Rotation - Round-robin rotation for multiple API keys
- 🎯 Type Safety - Strongly-typed models with helper methods
[dependencies]
cryptopay = "0.1"
tokio = { version = "1", features = ["full"] }
rust_decimal = "1.33"use cryptopay::*;
use rust_decimal::Decimal;
#[tokio::main]
async fn main() -> Result<()> {
let client = EtherscanClient::new("your-api-key")?;
let verifier = PaymentVerifier::new(client);
let payment = PaymentRequest::eth(
Decimal::new(1, 1), // 0.1 ETH
"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0",
12, // confirmations
);
match verifier.verify_payment(&payment).await? {
VerificationResult::Confirmed { tx_hash, .. } => {
println!("✅ Payment confirmed: {}", tx_hash);
}
_ => println!("⏳ Payment pending or not found"),
}
Ok(())
}- 📚 API Documentation
- 📖 User Guide
- 🚀 Examples
- 📝 CHANGELOG
See the examples/ directory for complete examples:
basic_payment.rs- ETH payment verificationtoken_payment.rs- ERC20 token verificationpayment_monitor.rs- Real-time monitoring with callbacks
Run examples:
ETHERSCAN_API_KEY=your-key cargo run --example basic_paymentexport ETHERSCAN_API_KEY="your-api-key"
export ETHERSCAN_RATE_LIMIT=5
export ETHERSCAN_CACHE_TTL=300let config = ClientConfig::builder()
.api_key("key1")
.api_key("key2") // Multiple keys for rotation
.rate_limit(10) // Higher limit for PRO plan
.testnet() // Use Sepolia testnet
.build()?;
let client = EtherscanClient::with_config(config)?;// Native ETH
Currency::ETH
// Predefined tokens
Currency::usdt() // Tether (6 decimals)
Currency::usdc() // USD Coin (6 decimals)
Currency::dai() // Dai (18 decimals)
// Custom ERC20
Currency::erc20("0xcontract...", 18)- Visit Etherscan
- Create an account
- Go to API-KEYs section
- Generate a free API key
Licensed under either of:
- MIT license LICENSE
at your option.
Contributions welcome! Please feel free to submit a Pull Request.