-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbatch_transfer.py
More file actions
60 lines (49 loc) · 2.12 KB
/
batch_transfer.py
File metadata and controls
60 lines (49 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from ton_core import Address, NetworkGlobalID, to_nano
from tonutils.clients import ToncenterClient
from tonutils.contracts import (
TONTransferBuilder,
WalletV4R2,
)
# Mnemonic phrase — 24 words (TON-native) or 12/18/24 words (BIP-39 import)
# Used to derive the wallet's private key
MNEMONIC = "word1 word2 word3 ..."
async def main() -> None:
# Initialize HTTP client for TON blockchain interaction
# NetworkGlobalID.MAINNET (-239) for production
# NetworkGlobalID.TESTNET (-3) for testing
client = ToncenterClient(network=NetworkGlobalID.MAINNET)
await client.connect()
# Create wallet instance from mnemonic (full access mode)
# Returns: (wallet, public_key, private_key, mnemonic)
wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)
# Send multiple transfers in a single transaction (batch transfer)
# WalletV4 supports up to 4 messages per transaction
# For more than 4 messages, use WalletV5*, WalletHighload* or WalletPreprocessed*
# Can mix TONTransferBuilder, NFTTransferBuilder, and JettonTransferBuilder
msg = await wallet.batch_transfer_message(
[
TONTransferBuilder(
destination=Address("UQ..."),
amount=to_nano(0.01), # 0.01 TON in nanotons
body="Hello from tonutils!",
),
TONTransferBuilder(
destination=Address("UQ..."),
amount=to_nano(0.01), # 0.01 TON in nanotons
body="Hello from tonutils!",
),
TONTransferBuilder(
destination=Address("UQ..."),
amount=to_nano(0.01), # 0.01 TON in nanotons
body="Hello from tonutils!",
),
]
)
# Normalized hash of the signed external message (computed locally before sending)
# Not a blockchain transaction hash — use it to track whether the message
# was accepted on-chain (e.g. via explorers, API queries, or your own checks)
print(f"Transaction hash: {msg.normalized_hash}")
await client.close()
if __name__ == "__main__":
import asyncio
asyncio.run(main())