Files
pyfragment/main.py
T
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

72 lines
2.2 KiB
Python

import asyncio
import logging
from app.core import setup_logging
from app.methods import buy_premium, buy_stars, topup_ton
logger = logging.getLogger(__name__)
async def topup_ton_example():
logger.info("Starting TON topup example")
# @bohd4nx - target username, 100 - TON amount (integer 1-1000000000 (one billion))
result = await topup_ton("@bohd4nx", 100)
if result["success"]:
data = result["data"]
logger.info(f"TON topup successful: {data['amount']} TON sent to {data['username']}")
logger.info(f"Transaction ID: {data['transaction_id']}")
else:
logger.error(f"TON topup failed: {result['error']}")
async def buy_premium_example():
logger.info("Starting Premium purchase example")
# @bohd4nx - target username, 12 - months duration (3, 6, or 12 only)
result = await buy_premium("@bohd4nx", 12)
if result["success"]:
data = result["data"]
logger.info(
f"Premium purchase successful: {data['months']} months sent to {data['username']}"
)
logger.info(f"Transaction ID: {data['transaction_id']}")
else:
logger.error(f"Premium purchase failed: {result['error']}")
async def buy_stars_example():
logger.info("Starting Stars purchase example")
# @bohd4nx - target username, 1000000 - stars amount (integer 50-1000000 (one million))
result = await buy_stars("@bohd4nx", 1000000)
if result["success"]:
data = result["data"]
logger.info(f"Stars purchase successful: {data['amount']} stars sent to {data['username']}")
logger.info(f"Transaction ID: {data['transaction_id']}")
else:
logger.error(f"Stars purchase failed: {result['error']}")
async def main():
setup_logging()
logger.info("Starting Fragment API by @bohd4nx - examples")
await topup_ton_example()
await buy_premium_example()
await buy_stars_example()
logger.info("All examples completed")
if __name__ == "__main__":
logger.info("Fragment API by @bohd4nx - Usage Examples")
logger.info("Supported username formats: @username, username")
logger.info("Limits: TON minimum 1, Premium 3/6/12 months, Stars minimum 50")
logger.info("Setup: Copy .env.example to .env and fill all fields")
asyncio.run(main())