Fragment Donor SDKSource

Version 0.1.3 · Registry installation commands use exact versions.

Go SDK for Telegram Stars and Premium

Install the independent Fragment Donor Go 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: Go 1.23+. 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 Go. 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

go get github.com/usnuz/fragment-donor-sdk/go@v0.1.3

Example

package main

import (
    "context"
    "errors"
    "os"
    "time"
    donor "github.com/usnuz/fragment-donor-sdk/go"
)

func main() {
    client, err := donor.NewClient(donor.Config{
        BaseURL: donor.DefaultBaseURL,
        Timeout: 30 * time.Second,
        ConnectTimeout: 5 * time.Second,
        Credentials: donor.Credentials{
            Mnemonic: os.Getenv("FRAGMENT_MNEMONIC"),
            Cookie: os.Getenv("FRAGMENT_COOKIE"),
            WalletVersion: "auto", // auto, v5r1, v4r2, v3r2
            ProviderKey: os.Getenv("TONCONSOLE_API_KEY"), // optional provider key
        },
    })
    if err != nil { return }
    ctx := context.Background()
    user, err := client.GetUserInfo(ctx, "durov")
    _ = user
    if err != nil { return }
    balance, err := client.WalletBalance(ctx)
    _ = balance // TON and USDTTON are exact decimal strings.
    if err != nil { return }

    // Real-funds operations require both opt-in and one selected purchase.
    if os.Getenv("FRAGMENT_ALLOW_PURCHASES") != "yes" { return }
    switch os.Getenv("FRAGMENT_PURCHASE_KIND") {
    case "stars":
        _, err = client.BuyStars(ctx, "durov", 50, "usdt_ton")
    case "premium":
        _, err = client.BuyPremium(ctx, "durov", 3, "ton")
    default:
        return
    }
    var apiErr *donor.Error
    if errors.As(err, &apiErr) {
        if apiErr.OutcomeUnknown {
            _ = apiErr.Details["tx_hash"] // reconcile manually; do not repeat.
        }
        _ = apiErr.RetryAfter // communicate wait, never auto-replay purchase.
    }
}

Source · go

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