Warning
Демонстрационный код: Данный проект является демонстрацией работы больше с блокчейном, чем с фрагментом и был написан в образовательных целях. Он требует доработок для стабильного использования в реальных условиях (продакшене).
Этот скрипт автоматизирует процесс покупки Telegram Stars на платформе Fragment. Он включает в себя функции для создания и инициализации кошелька TON, а также для выполнения самих транзакций.
Подробный разбор процесса статье на Lolzteam.
- Создание кошелька: Генерация нового кошелька TON любой поддерживаемой версии (например,
v3r1,v3r2,v4r2) с сохранением данных (адрес, мнемоника, ключи) в файл. - Инициализация кошелька: Развертывание контракта кошелька в сети TON, что необходимо для его активации.
- Автоматическая покупка: Скрипт самостоятельно получает все необходимые данные для платежа (адрес, сумму, payload) и отправляет транзакцию.
- Гибкая настройка: Возможность работы как в основной сети (mainnet), так и в тестовой (testnet).
- Получение данных для платежа (
PaymentGet.py):- Скрипт использует ваши
cookiesдля аутентификации на Fragment. - Отправляется запрос для получения ID получателя по его
@username. - Инициируется запрос на покупку, в результате которого Fragment предоставляет временный адрес кошелька, точную сумму в TON и специальную полезную нагрузку (
payload).
- Скрипт использует ваши
- Отправка транзакции (
Transactions.py):- Используя данные вашего кошелька (из
wallets_data.txt), скрипт формирует транзакцию. - На полученный от Fragment временный адрес отправляется нужная сумма TON с обязательным указанием
payload. - После успешной обработки этой транзакцией сетью TON, Fragment зачисляет "звезды" указанному получателю.
- Используя данные вашего кошелька (из
Сначала скопируйте репозиторий на свой компьютер и установите необходимые библиотеки.
git clone <URL репозитория>
cd <папка репозитория>
pip install -r requirements.txtСкрипт включает утилиты для работы с кошельками.
-
Создайте кошелек. Вы можете использовать встроенную функцию
create_wallet. Для этого создайте временный файл, например,generate_wallet.py, со следующим кодом и запустите его:# generate_wallet.py from wallet.WalletUtils import WalletUtils wallet_utils = WalletUtils() # Вы можете указать любую версию, например "v3r2" или "v4r2" wallet_utils.create_wallet(version="v4r2", save_to_file=True, save_dir="created_wallets/wallets_data.txt") print("Кошелек успешно создан! Данные сохранены в created_wallets/wallets_data.txt")
После запуска в файле
created_wallets/wallets_data.txtпоявятся все данные вашего нового кошелька, включая мнемоническую фразу. -
Пополните кошелек. Скопируйте
wallet_addressиз файла и отправьте на него немного TON (например, 1-2 TON) для оплаты комиссий и будущих покупок. Это обязательный шаг перед инициализацией!
Новый кошелек нужно активировать (развернуть его контракт в сети).
-
Убедитесь, что кошелек пополнен.
-
Создайте еще один временный файл, например
init_wallet.py, со следующим кодом:# init_wallet.py import json from wallet.WalletUtils import WalletUtils with open("created_wallets/wallets_data.txt", "r") as f: mnemonics = json.load(f)['mnemonics'] wallet_utils = WalletUtils() wallet_utils.init_wallet(mnemonics=mnemonics)
-
Запустите его. Если все пройдет успешно, в консоли появится сообщение
Wallet inited!.
Для взаимодействия с API Fragment скрипту нужны ваши сессионные cookie.
- Установите в браузер расширение для управления cookie, например, EditThisCookie.
- Откройте сайт Fragment и авторизуйтесь через Telegram.
- Нажмите на иконку расширения, найдите и скопируйте значения для
stel_dt,stel_ssid,stel_tokenиstel_ton_token. - Вставьте эти значения в соответствующие поля в файле
cookies.json.
После выполнения всех шагов настройки вы готовы к покупке.
- Запустите главный файл:
python main.py
- Введите имя пользователя получателя (например,
durov). - Введите желаемое количество "звезд".
Скрипт выведет в консоль информацию о процессе и результат выполнения.
- Безопасность: Никогда не делитесь файлами
cookies.jsonиwallets_data.txtс посторонними. Они содержат данные для доступа к вашему аккаунту и кошельку. - Комиссии: Убедитесь, что на вашем кошельке достаточно средств для покрытия не только стоимости "звезд", но и сетевой комиссии TON.
Warning
Demonstration Code: This project is more of a demonstration of working with the blockchain than with Fragment itself, and it was created for educational purposes. It requires further refinement for stable use in a real production environment.
This script automates the process of purchasing Telegram Stars on the Fragment platform. It includes functions for creating and initializing a TON wallet, as well as for executing the transactions themselves.
A detailed breakdown of the code-writing process and its logic can be found in the article on Lolzteam (in Russian).
- Wallet Creation: Generate a new TON wallet of any supported version (e.g.,
v3r1,v3r2,v4r2) and save its data (address, mnemonics, keys) to a file. - Wallet Initialization: Deploy the wallet's contract to the TON network, which is necessary for its activation.
- Automated Purchase: The script automatically retrieves all necessary payment data (address, amount, payload) and sends the transaction.
- Flexible Configuration: Ability to operate on both the mainnet and testnet.
- Get Payment Data (
PaymentGet.py):- The script uses your
cookiesto authenticate on Fragment. - A request is sent to get the recipient's ID based on their
@username. - A purchase request is initiated, from which Fragment provides a temporary wallet address, the exact amount in TON, and a special payload.
- The script uses your
- Send Transaction (
Transactions.py):- Using your wallet data (from
wallets_data.txt), the script creates a transaction. - The required amount of TON is sent to the temporary address received from Fragment, with the mandatory
payloadincluded. - After the TON network successfully processes this transaction, Fragment credits the Stars to the specified recipient.
- Using your wallet data (from
First, clone the repository to your computer and install the necessary libraries.
git clone <repository URL>
cd <repository folder>
pip install -r requirements.txtThe script includes utilities for wallet management.
-
Create a wallet. You can use the built-in
create_walletfunction. Create a temporary file, e.g.,generate_wallet.py, with the following code and run it:# generate_wallet.py from wallet.WalletUtils import WalletUtils wallet_utils = WalletUtils() # You can specify any version, e.g., "v3r2" or "v4r2" wallet_utils.create_wallet(version="v4r2", save_to_file=True, save_dir="created_wallets/wallets_data.txt") print("Wallet created successfully! Data saved to created_wallets/wallets_data.txt")
After running, the
created_wallets/wallets_data.txtfile will contain all your new wallet's data, including the mnemonic phrase. -
Fund your wallet. Copy the
wallet_addressfrom the file and send some TON to it (e.g., 1-2 TON) to cover fees and future purchases. This is a mandatory step before initialization!
A new wallet needs to be activated (its contract deployed on the network).
-
Ensure the wallet is funded.
-
Create another temporary file, e.g.,
init_wallet.py, with the following code:# init_wallet.py import json from wallet.WalletUtils import WalletUtils with open("created_wallets/wallets_data.txt", "r") as f: mnemonics = json.load(f)['mnemonics'] wallet_utils = WalletUtils() wallet_utils.init_wallet(mnemonics=mnemonics)
-
Run it. If successful, you will see the message
Wallet inited!in the console.
The script needs your session cookies to interact with the Fragment API.
- Install a cookie management extension in your browser, such as EditThisCookie.
- Go to the Fragment website and log in via Telegram.
- Click the extension's icon, find and copy the values for
stel_dt,stel_ssid,stel_token, andstel_ton_token. - Paste these values into the corresponding fields in the
cookies.jsonfile.
After completing all setup steps, you are ready to make a purchase.
- Run the main file:
python main.py
- Enter the recipient's username (e.g.,
durov). - Enter the desired amount of Stars.
The script will output information about the process and the result to the console.
- Security: Never share your
cookies.jsonandwallets_data.txtfiles with anyone. They contain access credentials to your account and wallet. - Fees: Ensure you have enough funds in your wallet to cover not only the cost of the Stars but also the TON network fees.