A fully async client for the Fragment.com API. One call returns a ready-to-sign TON transaction to purchase Stars, gift Premium, or top up TON — pay in TON or USDT.
1import asyncio 2from afragment import AsyncFragmentClient, nano_to_ton 3 4async def main(): 5 async with AsyncFragmentClient( 6 fragment_hash=HASH, fragment_cookie=COOKIE, 7 ) as client: 8 # one call → ready-to-sign TON transaction 9 result = await client.buy_stars( 10 "durov", 100, wallet, payment_method="ton", 11 ) 12 13 tx = result["transaction"]["messages"][0] 14 print(f"To: {result['recipient']['name']}") 15 print(f"Pay: {nano_to_ton(int(tx['amount']))} TON") 16 17asyncio.run(main())
Pass a username, an amount and your wallet address — every method returns a ready-to-sign TON transaction with recipient, price and payload.
Buy Stars for any @username and get back a signable transaction in one call.
Gift Telegram Premium for 3, 6 or 12 months to any username.
Top up a Fragment TON balance by any whole amount, on-chain.
Every purchase method shares the same signature and return shape. Validation runs before any network call.
| Method | Parameters | Validation |
|---|---|---|
| buy_stars(username, quantity, wallet, payment_method) | Purchase Telegram Stars | quantity ≥ 50 |
| buy_premium(username, months, wallet, payment_method) | Gift Telegram Premium | months ∈ 3 · 6 · 12 |
| buy_ton_topup(username, amount, wallet, payment_method) | TON balance topup | amount ≥ 1, whole |
afragment authenticates with your own Fragment.com session — grab the hash and cookie once from your browser.
You need FRAGMENT_HASH and FRAGMENT_COOKIE from a logged-in session.
?hash= URL param; COOKIE is in the request Cookie header.Rich, typed exceptions — all inherit from FragmentAPIError.
Decode transaction payloads and convert between nanoTON and TON without pulling in the TON SDK.
Async, typed, MIT licensed — depends only on aiohttp.