|
|
1 tydzień temu | |
|---|---|---|
| .. | ||
| examples | 1 tydzień temu | |
| src | 1 tydzień temu | |
| Cargo.toml | 1 tydzień temu | |
| README.md | 1 tydzień temu | |
Rust client SDK for the NpubCash v2 API.
use cdk_npubcash::{NpubCashClient, JwtAuthProvider};
use nostr_sdk::Keys;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let base_url = "https://npubx.cash".to_string();
let keys = Keys::generate();
let auth_provider = JwtAuthProvider::new(base_url.clone(), keys);
let client = NpubCashClient::new(base_url, std::sync::Arc::new(auth_provider));
// Fetch all quotes
let quotes = client.get_quotes(None).await?;
println!("Found {} quotes", quotes.len());
// Fetch quotes since timestamp
let recent_quotes = client.get_quotes(Some(1234567890)).await?;
// Update mint URL setting
client.set_mint_url("https://example-mint.tld").await?;
Ok(())
}
The SDK includes several examples to help you get started:
basic_usage.rs - Demonstrates fetching quotes and basic client usagemanage_settings.rs - Illustrates settings management (mint URL)create_and_wait_payment.rs - Demonstrates creating a npub.cash address and monitoring for paymentsNote: Quotes are always locked by default on the NPubCash server for security. The ability to toggle quote locking has been removed from the SDK.
Run an example with:
cargo run --example basic_usage
Set environment variables to customize behavior:
export NPUBCASH_URL=https://npubx.cash
export NOSTR_NSEC=nsec1... # Optional: use specific Nostr keys
cargo run --example create_and_wait_payment
The SDK uses NIP-98 (Nostr HTTP Auth) to authenticate with the NpubCash service:
MIT