gofragment

package module
v0.0.0-...-9d5ebec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 27 Imported by: 0

README

gofragment

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.

Features

  • 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

Installation

go get github.com/Locon213/gofragment

Quick Start

package 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)
}

Configuration

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
Blockchain Providers
Credentials

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.

API Reference

Client Methods
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
Error Types

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

License

MIT

Documentation

Index

Constants

View Source
const (
	FragmentDomain  = "fragment.com"
	FragmentBaseURL = "https://" + FragmentDomain

	StarsPage           = FragmentBaseURL + "/stars/buy"
	StarsGiveawayPage   = FragmentBaseURL + "/stars/giveaway"
	PremiumPage         = FragmentBaseURL + "/premium/gift"
	PremiumGiveawayPage = FragmentBaseURL + "/premium/giveaway"
	AdsTopupPage        = FragmentBaseURL + "/ads/topup"
	NumbersPage         = FragmentBaseURL + "/numbers"
	GiftsPage           = FragmentBaseURL + "/gifts"

	DefaultTimeout = 30 * time.Second
)
View Source
const (
	StarsPurchaseMin = 50
	StarsPurchaseMax = 10_000_000

	StarsGiveawayMin = 500
	StarsGiveawayMax = 1_000_000

	StarsWinnersMin = 1
	StarsWinnersMax = 15

	PremiumWinnersMin = 1
	PremiumWinnersMax = 24_000

	GramTopupMin = 1
	GramTopupMax = 1_000_000_000

	MinGramBalance = 0.33
	MinUSDTBalance = 0.75
)
View Source
const USDTGramMasterAddress = "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs"

Variables

View Source
var BaseHeaders = map[string]string{
	"accept":             "application/json, text/javascript, */*; q=0.01",
	"accept-language":    "en-US,en;q=0.9,uk;q=0.8,ru;q=0.7",
	"content-type":       "application/x-www-form-urlencoded; charset=UTF-8",
	"origin":             FragmentBaseURL,
	"priority":           "u=1, i",
	"sec-ch-ua":          `"Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147"`,
	"sec-ch-ua-mobile":   "?1",
	"sec-ch-ua-platform": `"Android"`,
	"sec-fetch-dest":     "empty",
	"sec-fetch-mode":     "cors",
	"sec-fetch-site":     "same-origin",
	"user-agent":         "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Mobile Safari/537.36",
	"x-requested-with":   "XMLHttpRequest",
}
View Source
var MnemonicWordCountsValid = map[int]struct{}{12: {}, 24: {}}
View Source
var PremiumMonthsValid = map[int]struct{}{3: {}, 6: {}, 12: {}}
View Source
var RequiredCookieKeys = [4]string{"stel_ssid", "stel_dt", "stel_token", "stel_ton_token"}

Functions

This section is empty.

Types

type APIProvider

type APIProvider string
const (
	ProviderLiteclient APIProvider = "liteclient"
	ProviderTonapi     APIProvider = "tonapi"
	ProviderToncenter  APIProvider = "toncenter"
)

func ValidAPIProviders

func ValidAPIProviders() []APIProvider

func (APIProvider) Valid

func (p APIProvider) Valid() bool

type AdsRechargeResult

type AdsRechargeResult struct {
	TransactionID string
	Amount        int
}

func (*AdsRechargeResult) String

func (r *AdsRechargeResult) String() string

type AdsTopupResult

type AdsTopupResult struct {
	TransactionID string
	Username      string
	Amount        int
}

func (*AdsTopupResult) String

func (r *AdsTopupResult) String() string

type AlreadySubscribedError

type AlreadySubscribedError struct{ FragmentAPIError }

func ErrPremiumActive

func ErrPremiumActive() *AlreadySubscribedError

type AnonymousNumberError

type AnonymousNumberError struct{ FragmentAPIError }

func ErrNumberNotOwned

func ErrNumberNotOwned(number string) *AnonymousNumberError

func ErrTerminateFailed

func ErrTerminateFailed(number string, exc error) *AnonymousNumberError

type AuctionFilter

type AuctionFilter string
const (
	FilterAuction   AuctionFilter = "auction"
	FilterSale      AuctionFilter = "sale"
	FilterSold      AuctionFilter = "sold"
	FilterAvailable AuctionFilter = ""
)

type AuctionItem

type AuctionItem struct {
	Slug   string `json:"slug"`
	Name   string `json:"name"`
	Status string `json:"status"`
	Price  string `json:"price"`
	Date   string `json:"date"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(seed, apiKey string, cookies any, opts ...Option) (*Client, error)

func (*Client) APIKey

func (c *Client) APIKey() string

func (*Client) APIProvider

func (c *Client) APIProvider() APIProvider

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, data map[string]any, pageURL string) (map[string]any, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) GetLoginCode

func (c *Client) GetLoginCode(ctx context.Context, number string) (*LoginCodeResult, error)

func (*Client) GetWallet

func (c *Client) GetWallet(ctx context.Context) (*WalletInfo, error)

func (*Client) GiveawayPremium

func (c *Client) GiveawayPremium(ctx context.Context, channel string, winners int, months int, opts ...GiveawayOption) (*PremiumGiveawayResult, error)

func (*Client) GiveawayStars

func (c *Client) GiveawayStars(ctx context.Context, channel string, winners, amount int, opts ...GiveawayOption) (*StarsGiveawayResult, error)

func (*Client) Logger

func (c *Client) Logger() *slog.Logger

func (*Client) PurchasePremium

func (c *Client) PurchasePremium(ctx context.Context, username string, months int, opts ...PurchaseOption) (*PremiumResult, error)

func (*Client) PurchaseStars

func (c *Client) PurchaseStars(ctx context.Context, username string, amount int, opts ...PurchaseOption) (*StarsResult, error)

func (*Client) RechargeAds

func (c *Client) RechargeAds(ctx context.Context, account string, amount int) (*AdsRechargeResult, error)

func (*Client) SearchGifts

func (c *Client) SearchGifts(ctx context.Context, opts ...SearchOption) (*GiftsResult, error)

func (*Client) SearchNumbers

func (c *Client) SearchNumbers(ctx context.Context, opts ...SearchOption) (*NumbersResult, error)

func (*Client) SearchUsernames

func (c *Client) SearchUsernames(ctx context.Context, opts ...SearchOption) (*UsernamesResult, error)

func (*Client) Seed

func (c *Client) Seed() string

func (*Client) TerminateSessions

func (c *Client) TerminateSessions(ctx context.Context, number string) (*TerminateSessionsResult, error)

func (*Client) ToggleLoginCodes

func (c *Client) ToggleLoginCodes(ctx context.Context, number string, canReceive bool) error

func (*Client) TopupGram

func (c *Client) TopupGram(ctx context.Context, username string, amount int, opts ...PurchaseOption) (*AdsTopupResult, error)

func (*Client) WalletVersion

func (c *Client) WalletVersion() WalletVersion

type ConfigurationError

type ConfigurationError struct{ FragmentError }

func ErrInvalidGramAmount

func ErrInvalidGramAmount() *ConfigurationError

func ErrInvalidMnemonic

func ErrInvalidMnemonic(count int) *ConfigurationError

func ErrInvalidMonths

func ErrInvalidMonths() *ConfigurationError

func ErrInvalidPaymentMethod

func ErrInvalidPaymentMethod(method PaymentMethod) *ConfigurationError

func ErrInvalidStarsAmount

func ErrInvalidStarsAmount() *ConfigurationError

func ErrInvalidStarsPerWinner

func ErrInvalidStarsPerWinner() *ConfigurationError

func ErrInvalidUsername

func ErrInvalidUsername(username string) *ConfigurationError

func ErrInvalidWinnersPremium

func ErrInvalidWinnersPremium() *ConfigurationError

func ErrInvalidWinnersStars

func ErrInvalidWinnersStars() *ConfigurationError

func ErrMissingVars

func ErrMissingVars(keys ...string) *ConfigurationError

func ErrUnsupportedProvider

func ErrUnsupportedProvider(provider string) *ConfigurationError

func ErrUnsupportedVersion

func ErrUnsupportedVersion(version string) *ConfigurationError

type CookieError

type CookieError struct{ FragmentError }

func ErrBrowserReadFailed

func ErrBrowserReadFailed(browser string, exc error) *CookieError

func ErrCookieExpired

func ErrCookieExpired(expires string) *CookieError

func ErrCookieMissingBrowserKeys

func ErrCookieMissingBrowserKeys(browser string, keys ...string) *CookieError

func ErrCookieMissingKeys

func ErrCookieMissingKeys(keys ...string) *CookieError

func ErrCookieReadFailed

func ErrCookieReadFailed(exc error) *CookieError

func ErrUnsupportedBrowser

func ErrUnsupportedBrowser(browser string) *CookieError

type CookieResult

type CookieResult struct {
	Cookies map[string]string
	Expires string
}

func GetCookiesFromBrowser

func GetCookiesFromBrowser(browser string) (*CookieResult, error)

func (*CookieResult) String

func (r *CookieResult) String() string

type FragmentAPIError

type FragmentAPIError struct{ FragmentError }

func ErrNoRequestID

func ErrNoRequestID(context string) *FragmentAPIError

type FragmentError

type FragmentError struct {
	Message string
	Cause   error
}

func (*FragmentError) Error

func (e *FragmentError) Error() string

func (*FragmentError) Unwrap

func (e *FragmentError) Unwrap() error

type FragmentPageError

type FragmentPageError struct{ FragmentAPIError }

func ErrBadStatus

func ErrBadStatus(status int, url string) *FragmentPageError

func ErrHashNotFound

func ErrHashNotFound(url string) *FragmentPageError

type GiftsResult

type GiftsResult struct {
	Items      []AuctionItem
	NextOffset int
	HasNext    bool
}

func (*GiftsResult) String

func (r *GiftsResult) String() string

type GiveawayOption

type GiveawayOption func(*giveawayOpts)

func WithGiveawayPaymentMethod

func WithGiveawayPaymentMethod(m PaymentMethod) GiveawayOption

type LoginCodeResult

type LoginCodeResult struct {
	Number         string
	Code           string
	ActiveSessions int
}

func (*LoginCodeResult) String

func (r *LoginCodeResult) String() string

type NumbersResult

type NumbersResult struct {
	Items        []AuctionItem
	NextOffsetID string
}

func (*NumbersResult) String

func (r *NumbersResult) String() string

type OperationError

type OperationError struct{ FragmentError }

type Option

type Option func(*Client)

func WithAPIProvider

func WithAPIProvider(p APIProvider) Option

func WithDefaultHeaders

func WithDefaultHeaders() Option

func WithHeaders

func WithHeaders(h map[string]string) Option

func WithTimeout

func WithTimeout(d time.Duration) Option

func WithWalletVersion

func WithWalletVersion(v WalletVersion) Option

type ParseError

type ParseError struct{ FragmentAPIError }

func ErrUnparseable

func ErrUnparseable(context string, exc error) *ParseError

type PaymentMethod

type PaymentMethod string
const (
	PayGRAM     PaymentMethod = "ton"
	PayUSDTGram PaymentMethod = "usdt_ton"

	PayUSDTEth  PaymentMethod = "usdt_eth"
	PayUSDTPol  PaymentMethod = "usdt_pol"
	PayUSDCEth  PaymentMethod = "usdc_eth"
	PayUSDCBase PaymentMethod = "usdc_base"
	PayUSDCPol  PaymentMethod = "usdc_pol"
)

func ValidPaymentMethods

func ValidPaymentMethods() []PaymentMethod

func (PaymentMethod) Valid

func (m PaymentMethod) Valid() bool

type PremiumGiveawayResult

type PremiumGiveawayResult struct {
	TransactionID string
	Channel       string
	Winners       int
	Amount        int
}

func (*PremiumGiveawayResult) String

func (r *PremiumGiveawayResult) String() string

type PremiumResult

type PremiumResult struct {
	TransactionID string
	Username      string
	Amount        int
}

func (*PremiumResult) String

func (r *PremiumResult) String() string

type PurchaseOption

type PurchaseOption func(*purchaseOpts)

func WithPaymentMethod

func WithPaymentMethod(m PaymentMethod) PurchaseOption

func WithShowSender

func WithShowSender(show bool) PurchaseOption

type SearchOption

type SearchOption func(*searchOpts)

func WithAttr

func WithAttr(attr map[string][]string) SearchOption

func WithCollection

func WithCollection(c string) SearchOption

func WithFilter

func WithFilter(f AuctionFilter) SearchOption

func WithOffset

func WithOffset(offset int) SearchOption

func WithOffsetID

func WithOffsetID(id string) SearchOption

func WithQuery

func WithQuery(q string) SearchOption

func WithSort

func WithSort(s SortOrder) SearchOption

func WithView

func WithView(v string) SearchOption

type SortOrder

type SortOrder string
const (
	SortPriceDesc SortOrder = "price_desc"
	SortPriceAsc  SortOrder = "price_asc"
	SortListed    SortOrder = "listed"
	SortEnding    SortOrder = "ending"
)

type StarsGiveawayResult

type StarsGiveawayResult struct {
	TransactionID string
	Channel       string
	Winners       int
	Amount        int
}

func (*StarsGiveawayResult) String

func (r *StarsGiveawayResult) String() string

type StarsResult

type StarsResult struct {
	TransactionID string
	Username      string
	Amount        int
}

func (*StarsResult) String

func (r *StarsResult) String() string

type SupportedBrowser

type SupportedBrowser string
const (
	BrowserChrome  SupportedBrowser = "chrome"
	BrowserFirefox SupportedBrowser = "firefox"
	BrowserEdge    SupportedBrowser = "edge"
	BrowserBrave   SupportedBrowser = "brave"
)

type TerminateSessionsResult

type TerminateSessionsResult struct {
	Number  string
	Message string
}

func (*TerminateSessionsResult) String

func (r *TerminateSessionsResult) String() string

type TransactionError

type TransactionError struct{ FragmentAPIError }

func ErrBroadcastFailed

func ErrBroadcastFailed(exc error) *TransactionError

func ErrBroadcastFailedSSL

func ErrBroadcastFailedSSL(exc error) *TransactionError

func ErrDuplicateSeqno

func ErrDuplicateSeqno() *TransactionError

func ErrInvalidPayload

func ErrInvalidPayload() *TransactionError

type UnexpectedError

type UnexpectedError struct{ OperationError }

func ErrUnexpected

func ErrUnexpected(exc error) *UnexpectedError

type UserNotFoundError

type UserNotFoundError struct{ FragmentAPIError }

func ErrNotAUser

func ErrNotAUser(username string) *UserNotFoundError

func ErrUserNotFound

func ErrUserNotFound(username string) *UserNotFoundError

type UsernamesResult

type UsernamesResult struct {
	Items        []AuctionItem
	NextOffsetID string
}

func (*UsernamesResult) String

func (r *UsernamesResult) String() string

type VerificationError

type VerificationError struct{ FragmentAPIError }

func ErrKYCRequired

func ErrKYCRequired() *VerificationError

type WalletError

type WalletError struct{ OperationError }

func ErrAccountInfoFailed

func ErrAccountInfoFailed(exc error) *WalletError

func ErrGramBalanceCheckFailed

func ErrGramBalanceCheckFailed(exc error) *WalletError

func ErrLowGramBalance

func ErrLowGramBalance(balance, required float64) *WalletError

func ErrLowUSDTBalance

func ErrLowUSDTBalance(balance, required float64) *WalletError

func ErrUSDTBalanceCheckFailed

func ErrUSDTBalanceCheckFailed(exc error) *WalletError

func ErrWalletInfoFailed

func ErrWalletInfoFailed(exc error) *WalletError

type WalletInfo

type WalletInfo struct {
	Address     string
	State       string
	GramBalance float64
	USDTBalance float64
}

func (*WalletInfo) String

func (w *WalletInfo) String() string

type WalletVersion

type WalletVersion string
const (
	WalletV4R2         WalletVersion = "V4R2"
	WalletV5R1         WalletVersion = "V5R1"
	WalletHighloadV2   WalletVersion = "HighloadV2"
	WalletHighloadV3R1 WalletVersion = "HighloadV3R1"
)

func ValidWalletVersions

func ValidWalletVersions() []WalletVersion

func (WalletVersion) Valid

func (v WalletVersion) Valid() bool

Directories

Path Synopsis
examples
get_cookies command
get_login_code command
giveaway_stars command
purchase_stars command
raw_api_call command
recharge_ads command
search_gifts command
search_numbers command
topup_gram command
wallet_info command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL