Mastering Bulk Transactions on TON with aiotx: A Guide to High-Load Wallets

Andreevichprudnikov
3 min readJul 8, 2024

--

The Telegram Open Network (TON) offers a powerful feature for high-volume transactions: the High-Load Wallet. This specialized wallet type allows for efficient bulk sending of transactions, making it ideal for applications that need to process multiple transfers quickly. In this guide, we’ll explore how to use the aiotx library to leverage TON’s High-Load Wallet for bulk transactions.

Prerequisites

Before we begin, make sure you have the aiotx library installed:

pip install aiotx

Setting Up the TON Client for High-Load Wallet

To use a High-Load Wallet, we need to initialize our TON client with the appropriate wallet version:

from aiotx.clients import AioTxTONClient
from aiotx.utils.tonsdk.contract.wallet import WalletVersionEnum
import asyncio
# For testnet
ton_client = AioTxTONClient(
"https://testnet.toncenter.com/api/v2",
workchain=0,
wallet_version=WalletVersionEnum.hv2
)
# For mainnet
# ton_client = AioTxTONClient(
# "https://toncenter.com/api/v2",
# wallet_version=WalletVersionEnum.hv2
# )

Note: We’re using the testnet in this example. For the testnet, we need to explicitly set `workchain=0` due to a current issue with toncenter’s testnet. This isn’t necessary for mainnet or other providers.

Generating a High-Load Wallet

If you don’t already have a High-Load Wallet, you can generate one like this:

async def generate_high_load_wallet():
mnemonic, address, raw_address = await ton_client.generate_address()
print(f"Mnemonic: {mnemonic}")
print(f"Address: {address}")
print(f"Raw Address: {raw_address}")
return mnemonic, address

mnemonic, address = asyncio.run(generate_high_load_wallet())

Make sure to securely store the mnemonic phrase — it’s the key to your wallet!

Deploying the High-Load Wallet

Before you can use your High-Load Wallet, you need to deploy it. This requires some TON in the wallet for gas fees:

async def deploy_high_load_wallet(mnemonic):
tx_id = await ton_client.deploy_wallet(mnemonic)
print(f"High-Load Wallet deployed. Transaction ID: {tx_id}")

asyncio.run(deploy_high_load_wallet(mnemonic))

Preparing Bulk Transactions

Now, let’s prepare a list of transactions for bulk sending:

recipients = [
{
"address": "EQBvW8Z5huBkMJYdnfAEM5JqTNkuWX3diqYENkWsIL0XggGG",
"amount": ton_client.to_nano(0.1),
"payload": "Payment 1",
"send_mode": 3,
},
{
"address": "EQD__________________________________________0vo",
"amount": ton_client.to_nano(0.2),
"payload": "Payment 2",
"send_mode": 3,
},
# Add more recipients as needed
]

Each recipient in the list is a dictionary containing:
- `address`: The recipient’s TON address
- `amount`: The amount to send in nanoTON (use `to_nano()` for conversion)
- `payload`: An optional message or comment for the transaction
- `send_mode`: The send mode (usually 3 for standard transfers)

Sending Bulk Transactions

With our recipients list prepared, we can now send the bulk transaction:

async def send_bulk(mnemonic, recipients):
tx_id = await ton_client.send_bulk(mnemonic, recipients)
print(f"Bulk transaction sent. Transaction ID: {tx_id}")

asyncio.run(send_bulk(mnemonic, recipients))

This single function call will send all the transactions in our recipients list in one go, significantly reducing the time and fees compared to sending them individually.

High-Load Wallets in TON provide a powerful tool for applications that need to process multiple transactions efficiently. With aiotx, leveraging this feature becomes straightforward, allowing you to send bulk transactions with just a few lines of code.

Remember to always test your applications thoroughly on the testnet before moving to mainnet. Happy bulk transacting on TON!

--

--