Fragment Donor SDKSource

Version 0.1.3 · Registry installation commands use exact versions.

PHP SDK for Telegram Stars and Premium

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

composer require fragment-donor/sdk:^0.1

Example

<?php

declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use FragmentDonor\{Client, Credentials, StarsRequest, PremiumRequest, RateLimitError, ServiceUnavailableError};

// Read-only by default. Never print or dump client credentials.
$client = new Client(credentials: new Credentials(
    mnemonic: getenv('FRAGMENT_MNEMONIC') ?: '',
    cookie: getenv('FRAGMENT_COOKIE') ?: '',
    providerKey: getenv('TONCONSOLE_API_KEY') ?: null,
));
try {
    $username = getenv('FRAGMENT_USERNAME') ?: 'durov';
    $user = $client->getUserInfo($username);
    echo 'Username: ' . $user->username() . PHP_EOL;
    if (getenv('FRAGMENT_MNEMONIC')) {
        $wallet = $client->walletBalance();
        echo 'TON balance: ' . $wallet->ton() . PHP_EOL;
        if (getenv('FRAGMENT_ALLOW_PURCHASES') === 'yes') {
            // Exactly one deliberate real-money gift, never both or a blind retry.
            $kind = getenv('FRAGMENT_PURCHASE_KIND');
            if ($kind === 'stars') {
                $client->buyStars(new StarsRequest($username, 50));
            } elseif ($kind === 'premium') {
                $client->buyPremium(new PremiumRequest($username, 3));
            } else {
                throw new LogicException('Select FRAGMENT_PURCHASE_KIND=stars or premium explicitly.');
            }
        }
    }
} catch (RateLimitError | ServiceUnavailableError $error) {
    echo 'Retry later: ' . ($error->retryAfter ?? 5) . ' seconds.' . PHP_EOL;
}

Source · php

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