bohd4nx efcdda6b74 refactor: migrate to tonutils 2.0.0 and restructure codebase
- Migrate from tonutils 0.5.x to 2.0.0 API:
  - ToncenterClient → TonapiClient with NetworkGlobalID
  - tonutils.client → tonutils.clients
  - tonutils.wallet → tonutils.contracts.wallet
  - pub_key.as_hex property, wallet.balance nanotons
  - async with client context manager

- Centralize TON client init into initialize_ton_client() in wallet.py
- Move process_transaction logic into wallet.py, transaction.py re-exports
- Add WALLET_VERSION config (V4R2/V5R1, default V5R1)
- Add WALLET_CLASSES and SUPPORTED_WALLET_VERSIONS to constants.py
- Restore balance check before broadcasting
- Wait for seqno confirmation after transfer (120×2s) to prevent duplicate seqno

- Fix Fragment hash fetching: use browser navigation headers
- Remove accept-encoding from BASE_HEADERS (httpx handles decompression)
- Add cookies.example.json template
- Add cookies.json to .gitignore
2026-03-05 05:47:27 +02:00

Fragment Logo

💎 Fragment API by @bohd4nx

Automate TON topups, Telegram Premium purchases, and Stars transactions via Fragment.com

Report Bug · Request Feature · Donate TON


Features

  • 💰 TON Advertisement Topups - Send TON for advertising campaigns and purchasing gifts (1-1,000,000,000 TON)
  • 👑 Telegram Premium Gifts - Purchase Premium subscriptions (3, 6, or 12 months)
  • Telegram Stars Purchases - Buy Stars for users (50-1,000,000 Stars)

🚀 Quick Start

1. Installation

git clone https://github.com/bohd4nx/FragmentAPI.git
cd FragmentAPI
pip install -r requirements.txt

2. Configuration

Copy example configuration and edit:

cp .env.example .env

Edit .env file:

SEED=word1 word2 word3 ... word24

API_KEY=your_ton_api_key_here

3. Getting Required Data

🍪 Fragment.com Cookies

Prerequisites: Login to your Telegram account and connect the TON wallet you want to use for payments.

  1. Install Cookie Editor Extension:

  2. Extract Cookies:

    • Open Fragment.com and ensure you're logged in
    • Refresh the page completely
    • Click on the Cookie Editor extension icon
    • Click "Export" button
    • Select "Header String" format
    • Copy the result and split it into JSON fields in cookies.json

Expected format (cookies.json in project root):

{
  "stel_ssid": "<SSID>",
  "stel_dt": "<STEL_DT>",
  "stel_token": "<TOKEN>",
  "stel_ton_token": "<TON_TOKEN>"
}

🔐 TON Wallet Seed Phrase

If you don't have a TON wallet yet:

  1. Download Tonkeeper:

  2. Create New Wallet:

    • Open Tonkeeper app
    • Tap "Create New Wallet"
    • IMPORTANT: Write down your 24-word seed phrase on paper
    • Store it securely - never share with anyone!
    • Complete wallet setup
  3. Get Your Seed Phrase:

    • If you already have a wallet, go to Settings → Backup
    • Enter your passcode
    • Copy the 24 words → paste to SEED in your .env file

Format: word1 word2 word3 ... word24

🔗 Fragment Hash

Hash is fetched automatically from Fragment pages at runtime. You no longer need to add HASH to .env.

🔑 TON API Key

  1. Get API Key:
    • Visit TON Console
    • Create account and login
    • Generate new API key
    • Copy the key → paste to API_KEY in your .env file

Alternative: You can also use TON API for getting API key.

4. Usage

Run Examples

python main.py

Programmatic Usage

from app.methods import FragmentTon, FragmentPremium, FragmentStars

# TON topup for ads
ton_client = FragmentTon()
result = await ton_client.topup_ton("@username", 5)

# Premium purchase
premium_client = FragmentPremium()
result = await premium_client.buy_premium("@username", 6)

# Stars purchase
stars_client = FragmentStars()
result = await stars_client.buy_stars("@username", 50)

Supported Operations

Operation Method Parameters Limits
TON Topup topup_ton(username, amount) Username, TON amount 1-1,000,000,000 TON
Premium Gift buy_premium(username, months) Username, duration 3, 6, or 12 months
Stars Purchase buy_stars(username, amount) Username, Stars amount 50-1,000,000 Stars

Username Formats

All methods accept various username formats:

  • @username (with @)
  • username (without @)

Made with ❤️ by @bohd4nx

Star this repo if you found it useful!

S
Description
Async Python client for the Fragment API — a unified toolkit to manage Telegram assets: purchase Stars and Premium, top up TON and Ads balances, run giveaways, manage anonymous numbers, and explore the marketplace for usernames, numbers, and gifts.
Readme MIT
259 KiB
Languages
Python 100%