SagaPay Rust SDK
Rust SDK for SagaPay - the world's first free, non-custodial blockchain payment gateway service provider. This library enables Rust developers to seamlessly integrate cryptocurrency payments without holding customer funds. With enterprise-grade security and zero transaction fees, SagaPay empowers merchants to accept crypto payments across multiple blockchains while maintaining full control of their digital assets.
Features
- Deposit address generation
- Withdrawal processing
- Transaction status checking
- Wallet balance fetching
- Webhook notifications (IPN)
- Multi-chain support (ERC20, BEP20, TRC20, POLYGON, SOLANA)
- Custom UDF field support
- Non-custodial architecture
- Async support with tokio
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
## Quick Start
```rust
{Client, Config, CreateDepositParams, NetworkType};
#[tokio::main]
-> Result<(), sagapay::Error> {
// Initialize the SagaPay client
= Client::new(Config {
"your-api-key".to_string(),
"your-api-secret".to_string(),
..Config::default()
});
// Create a deposit address
= client.create_deposit(CreateDepositParams {
NetworkType::BEP20,
"0".to_string(), // Use '0' for native coins
"1.5".to_string(),
"https://yourwebsite.com/webhook".to_string(),
Some("order-123".to_string()),
Some("TEMPORARY".to_string()),
}).await?;
"Deposit address created: {}", deposit.address);
"Expires at: {}", deposit.expires_at);
))
}
API Reference
Create Deposit
let deposit = client.create_deposit.await?;
Create Withdrawal
let withdrawal = client.create_withdrawal.await?;
Check Transaction Status
let status = client.check_transaction_status.await?;
Fetch Wallet Balance
let balance = client.fetch_wallet_balance.await?;
Handling Webhooks (IPN)
SagaPay sends webhook notifications to your specified ipnUrl when transaction statuses change. Use the WebhookHandler to process these notifications:
use ;
use HashMap;
// In your webhook endpoint handler:
async
Webhook Payload Format
When SagaPay sends a webhook to your endpoint, it will include the following payload:
Error Handling
The SDK provides a comprehensive error handling system using the thiserror crate:
match client.create_deposit.await
License
This SDK is released under the MIT License.
Support
For questions or support, please contact support@sagapay.net or visit https://sagapay.net.