tonutils library: creating and importing wallets, sending transactions, retrieving contract data, and calling get-methods. The snippets here are fragments for orientation — each topic has a full runnable version under Usage Examples.
Working with Wallets
Creating a Wallet
wallet— an instance ofWalletV4R2, ready to use.public_key— the wallet’s public key (PublicKey).private_key— the wallet’s private key (PrivateKey).mnemonic— list of 24 words (list[str]).
Importing a Wallet
From a mnemonic phrase:MNEMONIC— can be provided in one of two formats:- a string of space-separated words.
- a list of words.
private_key— aPrivateKey, constructed from raw bytes, a hex string, a base64 string, or an integer.
Wallet Examples
Full runnable scripts for creating, importing, and inspecting wallets on GitHub.
Sending Transactions
Single Transaction
destination— the recipient: a string with the address or anAddressobject.amount— amount in nanotons (int); useto_nano()to convert from TON (1 TON = 10^9 nanotons).body— comment as a string or custom data as aCell.
ExternalMessage. Its normalized_hash is the normalized hash of the signed external message, computed locally before sending — it is not the on-chain transaction hash. Use it to track whether the message was accepted on-chain (via explorers or API queries).
Batch Transfer
Allows sending multiple transfers in a single transaction:ExternalMessage (see Single Transaction for the meaning of normalized_hash).
V3 and V4 wallets support up to 4 messages per transaction. For more messages, use
WalletV5R1, WalletHighloadV3R1, or WalletPreprocessedV2.Send Mode
Thesend_mode parameter controls how the outgoing message is sent — for example, mode 128 carries the entire remaining balance of the wallet.
For more details on available send modes, see the official TON documentation.
Contract Information
Contract Balance
int) representing the contract balance in nanotons. Use to_amount() to convert nanotons to TON.
Contract Data
ContractInfo object; see ContractInfo Fields Overview for the full field reference.
Calling a Contract Method
Therun_get_method function allows invoking a contract’s get-method.
address— contract address as a string or anAddressobject.method_name— name of the get-method to call (str).stack— list of arguments, orNonefor no arguments.