Skip to main content

TonConnect

TonConnect is a Python library that allows you to connect to TON wallets, manage connections, handle messages, and send requests to the wallet. It provides a convenient way to interact with TON wallets and perform various operations.

Installation

To install TonConnect, you can use pip:

pip install ton-connect

Usage

TonConnect Class

The TonConnect class is responsible for managing connections to TON wallets. It provides methods to connect to a wallet, restore a connection, handle messages, start and stop listeners, and send requests to the wallet.

Initializing TonConnect

To initialize the TonConnect class, you need to provide the manifest URL and a storage instance. The manifest URL is the URL to the manifest file of your app, and the storage instance is used to store connection data. Note that the first argument to DictStorage is the user id.

from ton_connect.connector import TonConnect
from ton_connect.storage import DictBridgeStorage


manifest_url = "https://example.com/manifest.json"
storage = DictBridgeStorage("user_id")

ton_connect = TonConnect(manifest_url, storage)

Connecting to a Wallet

To connect to a wallet, you need to provide a WalletApp instance. The WalletApp class represents a wallet app and contains information such as the app name, bridge URL, and universal URL.

You can also use the TonConnect.get_wallets method to get a list of supported wallet apps.

from ton_connect.model.app.wallet import WalletApp
from ton_connect.connector import TonConnect

wallets = await TonConnect.get_wallets()
wallet = wallets[0]

connect_url = await ton_connect.connect(wallet)
print("Connect URL:", connect_url)

Restoring a Connection

To restore a connection to a wallet, you can use the restore_connection method. This method restores the connection using the stored connection data.

await ton_connect.restore_connection(wallet)

Sending Requests

The TonConnect class provides methods to send various requests to the wallet. For example, you can send a transaction request using the SendTransactionRequest class.

from ton_connect.model.app.request import SendTransactionRequest, SendTransactionMessage

request = SendTransactionRequest(
    address="0:1234567890abcdef",
    network=1,
    messages=[
        SendTransactionMessage(
            address="0:abcdef1234567890",
            amount="1000000000"
        )
    ]
)

response = await ton_connect.send(wallet.app_name, request)
print("Response:", response)

Listening for Wallet Events

The TonConnect class allows you to listen for wallet events by adding event listeners. You can add event listeners for events such as connect, disconnect, and errors.

from ton_connect.model.wallet.event import WalletEventName
from ton_connect.connector import ConnectorEvent

async def on_connect(event: ConnectorEvent):
    print("Connected:", event)

async def on_disconnect(event: ConnectorEvent):
    print("Disconnected:", event)

ton_connect.listen(WalletEventName.CONNECT, on_connect)
ton_connect.listen(WalletEventName.DISCONNECT, on_disconnect)

License

This project is licensed under the MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ton_connect_async-0.2.16.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ton_connect_async-0.2.16-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file ton_connect_async-0.2.16.tar.gz.

File metadata

  • Download URL: ton_connect_async-0.2.16.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.1 Darwin/24.2.0

File hashes

Hashes for ton_connect_async-0.2.16.tar.gz
Algorithm Hash digest
SHA256 ae7bc182fd8b5b9384f1e0e25e7a2b1752dde46cf79535b7cd5163e0102fca80
MD5 feef44ba4bde6cfb76836b049c90a9d7
BLAKE2b-256 3635d2ddc317510dda4f225ad57f2d183bbe92a983d91cbb7868480c8eee3730

See more details on using hashes here.

File details

Details for the file ton_connect_async-0.2.16-py3-none-any.whl.

File metadata

  • Download URL: ton_connect_async-0.2.16-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.1 Darwin/24.2.0

File hashes

Hashes for ton_connect_async-0.2.16-py3-none-any.whl
Algorithm Hash digest
SHA256 a6514bf5cabc492dbe7a5a3a0f862778e21727c65dd0b06e6ca8e07b92b40965
MD5 c489b5491ca83afc855bfac1524e9617
BLAKE2b-256 9b30cb38af7b0bc7d179bb5b8e8fd64c00eeee00b0013139788b0d179b2d2769

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page