Version 0.1.3 · Registry installation commands use exact versions.
C# / .NET SDK for Telegram Stars and Premium
Install the independent Fragment Donor C# / .NET 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: .NET 8+. 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 C# / .NET. 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
dotnet add package FragmentDonor.Sdk --version 0.1.3Example
using FragmentDonor.Sdk;
// Read-only by default. Never dump or serialize credentials.
var mnemonic = Environment.GetEnvironmentVariable("FRAGMENT_MNEMONIC") ?? "";
using var client = new FragmentDonorClient(new ClientOptions
{
Credentials = new WalletCredentials(mnemonic,
Environment.GetEnvironmentVariable("FRAGMENT_COOKIE"))
{
ProviderKey = Environment.GetEnvironmentVariable("TONCONSOLE_API_KEY"),
},
});
try
{
var username = Environment.GetEnvironmentVariable("FRAGMENT_USERNAME") ?? "durov";
var user = await client.GetUserInfoAsync(username);
Console.WriteLine("Username: " + user.Username);
if (!string.IsNullOrWhiteSpace(mnemonic))
{
var balance = await client.WalletBalanceAsync();
Console.WriteLine("TON balance: " + balance.Ton);
if (Environment.GetEnvironmentVariable("FRAGMENT_ALLOW_PURCHASES") == "yes")
{
// Exactly one deliberate real-money gift; never repeat blindly.
var kind = Environment.GetEnvironmentVariable("FRAGMENT_PURCHASE_KIND");
if (kind == "stars") await client.BuyStarsAsync(new StarsRequest(username, 50));
else if (kind == "premium") await client.BuyPremiumAsync(new PremiumRequest(username, 3));
else throw new ArgumentException("Select FRAGMENT_PURCHASE_KIND=stars or premium explicitly.");
}
}
}
catch (RateLimitException error) { Console.WriteLine($"Try later in {error.RetryAfter} seconds."); }
catch (ServiceUnavailableException error) { Console.WriteLine($"Try later in {error.RetryAfter} seconds."); }
Continue reading
Handle Telegram Stars API 429, Retry-After, and flood wait · Protect wallet credentials in API integrations · Fragment Donor API and SDK FAQ