Go client for the Fragment marketplace API. Buy Stars & Premium, run giveaways, top up GRAM (ex TON) and Ads balances, manage anonymous numbers, and search Fragment listings.
Disclaimer: This project is not affiliated with Fragment or Telegram.
- Purchase Telegram Stars and Premium for any user
- Run Stars and Premium giveaways for channels
- Top up GRAM (ex TON) balance and recharge Telegram Ads
- Manage anonymous numbers (login codes, session termination)
- Search marketplace for usernames, numbers, and gifts
- Fetch wallet info (address, state, GRAM & USDT balances)
- Raw Fragment API calls for advanced use cases
- Browser cookie extraction (Chrome, Firefox, Edge)
- Three blockchain API providers: liteclient (ADNL, no API key), tonapi, toncenter
go get github.com/Locon213/gofragmentpackage main
import (
"context"
"fmt"
"log"
gofragment "github.com/Locon213/gofragment"
)
func main() {
client, err := gofragment.NewClient(
"word1 word2 ... word24",
"YOUR_API_KEY",
map[string]string{
"stel_ssid": "...",
"stel_dt": "...",
"stel_token": "...",
"stel_ton_token": "...",
},
gofragment.WithAPIProvider(gofragment.ProviderTonapi),
gofragment.WithWalletVersion(gofragment.WalletV5R1),
)
if err != nil {
log.Fatal(err)
}
defer client.Close()
wallet, err := client.GetWallet(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("GRAM: %.4f | USDT: %.4f\n", wallet.GramBalance, wallet.USDTBalance)
stars, err := client.PurchaseStars(context.Background(),
"@username", 500,
gofragment.WithPaymentMethod(gofragment.PayGRAM),
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Sent %d Stars | tx: %s\n", stars.Amount, stars.TransactionID)
}| Option | Default | Description |
|---|---|---|
WithAPIProvider |
ProviderTonapi |
ProviderLiteclient, ProviderTonapi, or ProviderToncenter |
WithWalletVersion |
WalletV5R1 |
WalletV4R2, WalletV5R1, WalletHighloadV2, WalletHighloadV3R1 |
WithTimeout |
30s |
HTTP request timeout |
WithHeaders |
Browser-like | Custom HTTP headers |
- liteclient — Direct ADNL connection to TON lite servers. No API key needed. Fastest.
- tonapi — HTTP REST API via tonapi.io. Requires API key from tonconsole.com.
- toncenter — HTTP REST API via toncenter.com. Requires API key from @t.me/toncenter.
Fragment cookies: Log in to fragment.com and extract cookies (stel_ssid, stel_dt, stel_token, stel_ton_token).
Automatically from browser:
cookies, err := gofragment.GetCookiesFromBrowser("chrome")Seed phrase: 12- or 24-word mnemonic from your GRAM (ex TON) wallet.
| Method | Description |
|---|---|
GetWallet(ctx) |
Wallet address, state, GRAM & USDT balances |
PurchaseStars(ctx, username, amount, opts...) |
Send Telegram Stars |
PurchasePremium(ctx, username, months, opts...) |
Gift Telegram Premium |
GiveawayStars(ctx, channel, winners, amount, opts...) |
Stars giveaway |
GiveawayPremium(ctx, channel, winners, months, opts...) |
Premium giveaway |
TopupGram(ctx, username, amount, opts...) |
Top up GRAM balance |
RechargeAds(ctx, account, amount) |
Recharge Telegram Ads |
GetLoginCode(ctx, number) |
Get login code for anonymous number |
ToggleLoginCodes(ctx, number, canReceive) |
Enable/disable login codes |
TerminateSessions(ctx, number) |
Terminate all sessions for number |
SearchUsernames(ctx, opts...) |
Search username auctions |
SearchNumbers(ctx, opts...) |
Search number auctions |
SearchGifts(ctx, opts...) |
Search gifts marketplace |
Call(ctx, method, data, pageURL) |
Raw Fragment API call |
All errors implement the error interface and support errors.Is / errors.As:
| Error Type | Description |
|---|---|
ConfigurationError |
Invalid arguments |
CookieError |
Cookie issues |
FragmentAPIError |
Fragment API error |
UserNotFoundError |
User not found on Fragment |
AlreadySubscribedError |
User already has Premium |
TransactionError |
Transaction failed |
WalletError |
Insufficient balance |
VerificationError |
KYC required |
ParseError |
Response parse error |
MIT