CoinPayments Rust SDK
A comprehensive Rust client library for the CoinPayments API that provides easy access to cryptocurrency payment processing, wallet management, transaction handling, and more.
Features
- ๐ช Currencies: Get supported currencies, rates, and conversion information
- ๐ฑ Rates: Real-time exchange rates and market data
- ๐ธ Fees: Blockchain fee calculations and estimates
- ๐ Wallets: Create and manage wallets and addresses
- ๐ Transactions: Handle payments, withdrawals, and consolidations
- ๐งพ Invoices: Create and manage payment invoices
- ๐ Webhooks: Set up and manage webhook notifications
- ๐ ๏ธ Utils: Comprehensive utility functions for validation and formatting
Quick Start
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["full"] }
Basic Usage
use ;
async
API Structure
The SDK is organized into logical modules:
๐ช Currencies API
// Get all supported currencies
let currencies = client.get_currencies.await?;
// Get specific currency by ID
let bitcoin = client.get_currency_by_id.await?; // Bitcoin
// Get merchant's accepted currencies
let merchant_currencies = client.get_merchant_currencies.await?;
// Get currency limits for conversions
let limits = client.get_currency_limits.await?; // BTC to ETH
๐ฑ Exchange Rates API
use RateQuery;
// Get all exchange rates
let rates = client.get_rates.await?;
// Get specific rate
let btc_eth_rate = client.get_rate.await?; // BTC to ETH
// Get rates with filters
let btc_rates = client.get_rates.await?;
๐ธ Blockchain Fees API
use ;
// Calculate basic fees
let fees = client.calculate_blockchain_fee.await?; // Bitcoin
// Calculate fees with specific parameters
let fee_request = new
.with_amount
.with_priority;
let fees = client.calculate_blockchain_fee.await?;
// Get recommended fee for target confirmation time
let fee = client.get_recommended_fee.await?; // 30 minutes
๐ Wallets API
use ;
// Create a new wallet
let wallet_request = new
.with_permanent_addresses
.with_webhook;
let wallet = client.create_wallet.await?;
// List wallets
let wallets = client.get_wallets.await?;
// Get wallet addresses
let addresses = client.get_wallet_addresses.await?;
๐ Transactions API
use CreateSpendRequest;
// Create spend request (withdrawal)
let spend_request = new
.to_address
.with_note;
let spend = client.create_spend_request.await?;
// Confirm spend request
let transaction = client.confirm_spend_request.await?;
// Get transaction history
let transactions = client.get_transactions.await?;
๐งพ Invoices API
use ;
// Create an invoice
let invoice_request = new
.with_invoice_number
.with_buyer
.with_payment_currencies
.expires_in_minutes;
let invoice = client.create_invoice.await?;
// Get invoices
let invoices = client.get_invoices.await?;
// Get invoice payment status
let payment_status = client.get_invoice_payment_status.await?;
๐ Webhooks API
use ;
// Create client webhook for invoices
let webhook_request = new
.with_events
.with_secret;
let webhook = client.create_client_webhook.await?;
// Update wallet webhook
let wallet_webhook = WebhookConfig ;
client.update_wallet_webhook_v3.await?;
Webhook Verification
The SDK provides utilities for webhook verification:
use ;
async
Utility Functions
The SDK includes comprehensive utility functions:
use ;
// Format amounts
let formatted = format_amount; // "1.23"
// Convert to/from smallest units (satoshis, wei, etc.)
let satoshis = to_smallest_unit; // 100_000_000
let btc = from_smallest_unit; // 1.0
// Validate addresses and emails
let is_valid_btc = is_valid_bitcoin_address;
let is_valid_eth = is_valid_ethereum_address;
let is_valid_mail = is_valid_email;
Legacy API Support
For backward compatibility with the v1 API:
use CoinPaymentsLegacyClient;
use ;
// Create legacy client
let legacy_client = new;
// Use legacy methods
let rates = legacy_client.get_rates.await?;
let balances = legacy_client.get_balances.await?;
// Create transaction (legacy style)
let transaction_request = new
.with_buyer_email;
let transaction = legacy_client.create_transaction.await?;
Error Handling
The SDK provides comprehensive error handling:
use ;
match client.get_currencies.await
Testing
Run the tests:
Run the comprehensive example:
# Set your credentials as environment variables
API Reference
For detailed API documentation, visit:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- ๐ Documentation
- ๐ Issues
- ๐ฌ Discussions
Changelog
See CHANGELOG.md for a list of changes and version history.