| Crates.io | crypto-pay-api |
| lib.rs | crypto-pay-api |
| version | 0.1.2 |
| created_at | 2025-02-13 02:25:06.789086+00 |
| updated_at | 2025-08-03 00:07:38.681641+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 | 291,608 |
A type-safe Rust client for the Crypto Bot API with async support.
Add to your Cargo.toml:
[dependencies]
crypto-pay-api = "0.1.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
let params = CreateInvoiceParamsBuilder::new()
.asset(CryptoCurrencyCode::Ton)
.amount(dec!(10.5))
.description("Test payment".to_string())
.build(&client)
.await?;
let invoice = client.create_invoice(¶ms).await?;
println!("Payment URL: {}", invoice.pay_url);
Ok(())
}
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(WebhookHandlerConfigBuilder::new().build());
// Register payment callback
handler.on_update(|update| async move {
println!("Invoice paid: {:?}", update.payload);
Ok(())
});
// Start webhook server
// ... integrate with your web framework
}
See examples/axum_webhook.rs for an 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().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.