| Crates.io | crypto-pay-api |
| lib.rs | crypto-pay-api |
| version | 0.2.1 |
| created_at | 2025-02-13 02:25:06.789086+00 |
| updated_at | 2026-01-01 14:01:49.659335+00 |
| description | A Rust client library for Crypto Pay API provided by Telegram CryptoBot |
| homepage | |
| repository | https://github.com/escwxyz/cypto-pay-api |
| max_upload_size | |
| id | 1553714 |
| size | 293,044 |
A type-safe Rust client for the Crypto Bot API with async support.
Add to your Cargo.toml:
[dependencies]
crypto-pay-api = "0.2.1"
use crypto_pay_api::prelude::*;
#[tokio::main]
async fn main() -> Result<(), CryptoBotError> {
// Initialize client
let client = CryptoBot::builder()
.api_token("YOUR_API_TOKEN")
.build()?;
// Create an invoice using the builder pattern
let invoice = client.create_invoice()
.asset(CryptoCurrencyCode::Ton)
.amount(10.5) // Accepts numeric literals directly
.description("Test payment".to_string())
.execute()
.await?;
println!("Payment URL: {}", invoice.bot_invoice_url);
Ok(())
}
All API methods follow a consistent builder pattern:
client.api_method()
.optional_param(value)
.execute()
.await?
let invoice = client.create_invoice()
.asset(CryptoCurrencyCode::Ton)
.amount(100.0) // No need for dec!() macro
.description("Premium subscription".to_string())
.payload("user_123".to_string())
.execute()
.await?;
let invoices = client.get_invoices()
.asset(CryptoCurrencyCode::Ton)
.invoice_ids(vec![123, 456])
.count(50)
.execute()
.await?;
let success = client.delete_invoice(invoice_id)
.execute()
.await?;
let transfer = client.transfer()
.user_id(123456789)
.asset(CryptoCurrencyCode::Usdt)
.amount(50.0) // Flexible amount input
.spend_id("unique_id_123".to_string())
.comment("Payment for services".to_string())
.execute()
.await?;
let balances = client.get_balance()
.execute()
.await?;
for balance in balances {
println!("{}: {}", balance.currency_code, balance.available);
}
let rates = client.get_exchange_rates()
.execute()
.await?;
let stats = client.get_stats()
.start_at(Utc::now() - Duration::days(7))
.end_at(Utc::now())
.execute()
.await?;
create_invoice)get_invoices)delete_invoice)transfer)get_transfers)create_check)get_checks)delete_check)get_balance)get_exchange_rates)get_currencies)get_me)get_stats)use crypto_pay_api::prelude::*;
#[tokio::main]
async fn main() -> Result<(), CryptoBotError> {
let client = CryptoBot::builder()
.api_token("YOUR_API_TOKEN")
.build()?;
let mut handler = client.webhook_handler().build();
// Register payment callback
handler.on_update(|update| async move {
println!("Invoice paid: {:?}", update.payload);
Ok(())
});
// Start webhook server
// ... integrate with your web framework
Ok(())
}
See examples/axum_webhook.rs for a complete example using axum.
let client = CryptoBot::builder()
.api_token("YOUR_API_TOKEN")
.base_url("https://pay.crypt.bot/api")
.timeout(Duration::from_secs(30))
.build()?;
The library provides detailed error types:
match client.get_balance().execute().await {
Ok(balances) => {
for balance in balances {
println!("{}: {}", balance.currency_code, balance.available);
}
}
Err(CryptoBotError::ValidationError { kind, message, field }) => {
eprintln!("Validation error: {} (field: {:?})", message, field);
}
Err(e) => eprintln!("Other error: {}", e),
}
Contributions are welcome! Please check out our Contributing Guide.
This project is licensed under the MIT License - see the LICENSE file for details.