Fragment Donor SDKSource

Version 0.1.3 · Registry installation commands use exact versions.

Rust SDK for Telegram Stars and Premium

Install the independent Fragment Donor Rust SDK, check usernames, gift Stars/Premium, and handle rate limits safely.

Purchase requests transmit your wallet mnemonic and Fragment session/cookie to the API operator.

Runtime: Rust 1.99+. Version 0.1.3 is published; use the exact registry command shown on this page.

The client exposes username lookup, Stars purchase, Premium gift, and wallet balance with native naming for Rust. Required request bodies use form-urlencoded. Wallet balances remain decimal strings; unknown response fields are retained.

Configure a request timeout and wallet credentials on your backend. Read retries are opt-in and bounded; purchase calls never retry automatically. Review the package README for the exact constructor and error classes.

Install

cargo add fragment-donor-sdk@0.1.3

Example

use fragment_donor_sdk::{Client, Config, Credentials, ErrorKind};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new(Config {
        credentials: Credentials {
            mnemonic: std::env::var("FRAGMENT_MNEMONIC")?,
            cookie: std::env::var("FRAGMENT_COOKIE")?,
            provider_key: std::env::var("TONCONSOLE_API_KEY").unwrap_or_default(),
            ..Credentials::default()
        },
        ..Config::default()
    })?;
    let user = client.get_user_info("durov")?;
    let balance = client.wallet_balance()?;
    let _ = (user, balance.ton, balance.usdt_ton); // exact decimal strings

    // Real-funds operations require both opt-in and one selected purchase.
    if std::env::var("FRAGMENT_ALLOW_PURCHASES").as_deref() != Ok("yes") {
        return Ok(());
    }
    let result = match std::env::var("FRAGMENT_PURCHASE_KIND").as_deref() {
        Ok("stars") => client.buy_stars("durov", 50, Some("usdt_ton")),
        Ok("premium") => client.buy_premium("durov", 3, Some("ton")),
        _ => return Ok(()),
    };
    match result {
        Err(error) if error.kind == ErrorKind::PurchaseOutcomeUnknown || error.outcome_unknown => {
            let _ = error.details.get("tx_hash"); // reconcile manually; no replay
        }
        result => { let _ = result?; }
    }
    Ok(())
}

Source · rust

Continue reading

Handle Telegram Stars API 429, Retry-After, and flood wait · Protect wallet credentials in API integrations · Fragment Donor API and SDK FAQ

OpenAPI 3.0 · Postman collection