use cryptopay::{EtherscanClient, Currency, PaymentRequest, PaymentVerifier, VerificationResult};
use rust_decimal::Decimal;
use std::str::FromStr;
const USDT_CONTRACT: &str = "0xdAC17F958D2ee523a2206206994597C13D831ec7";
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv::dotenv().ok();
let api_key = std::env::var("ETHERSCAN_API_KEY")
.expect("ETHERSCAN_API_KEY environment variable not set");
let client = EtherscanClient::new(api_key)?;
let verifier = PaymentVerifier::new(client);
let payment_request = PaymentRequest {
amount: Decimal::from_str("100.0")?,
currency: Currency::ERC20 {
contract_address: USDT_CONTRACT.to_string(),
decimals: 6, },
recipient_address: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0".to_string(),
required_confirmations: 6, timeout_seconds: Some(3600), };
println!("Checking for USDT payment to {}", payment_request.recipient_address);
println!("Expected amount: {} USDT", payment_request.amount);
println!("Token contract: {}", USDT_CONTRACT);
println!("Required confirmations: {}", payment_request.required_confirmations);
println!();
match verifier.verify_payment(&payment_request).await? {
VerificationResult::Confirmed {
tx_hash,
confirmations,
} => {
println!("✓ USDT payment confirmed!");
println!(" Transaction: {}", tx_hash);
println!(" Confirmations: {}", confirmations);
}
VerificationResult::Pending {
tx_hash,
confirmations,
} => {
println!("⏳ USDT payment detected but pending confirmations");
println!(" Transaction: {}", tx_hash);
println!(" Confirmations: {}/{}", confirmations, payment_request.required_confirmations);
}
VerificationResult::NotFound => {
println!("✗ No matching USDT payment found");
}
VerificationResult::Failed { reason } => {
println!("✗ USDT payment verification failed: {}", reason);
}
}
let _usdc_payment = PaymentRequest {
amount: Decimal::from_str("50.0")?,
currency: Currency::usdc(), recipient_address: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0".to_string(),
required_confirmations: 6,
timeout_seconds: Some(3600),
};
println!("\nYou can also use predefined currencies:");
println!("- Currency::usdt()");
println!("- Currency::usdc()");
println!("- Currency::dai()");
Ok(())
}