ton-connect-async


Nameton-connect-async JSON
Version 0.2.18 PyPI version JSON
download
home_pagehttps://github.com/yurzs/ton-connect
SummaryPython SDK for TON Connect
upload_time2025-01-25 11:21:58
maintainerNone
docs_urlNone
authorYury Sokov
requires_python>=3.11
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
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.

```python
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.

```python
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.

```python
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.

```python
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.

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/yurzs/ton-connect",
    "name": "ton-connect-async",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": null,
    "author": "Yury Sokov",
    "author_email": "me@yurzs.dev",
    "download_url": "https://files.pythonhosted.org/packages/63/c9/d30142335f5183ccecf2038b53c791f1620121e7e697067faf44b436f144/ton_connect_async-0.2.18.tar.gz",
    "platform": null,
    "description": "# TonConnect\n\nTonConnect 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.\n\n## Installation\n\nTo install TonConnect, you can use pip:\n\n```bash\npip install ton-connect\n```\n\n## Usage\n\n### TonConnect Class\n\nThe `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.\n\n### Initializing TonConnect\n\nTo 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.\n\n```python\nfrom ton_connect.connector import TonConnect\nfrom ton_connect.storage import DictBridgeStorage\n\n\nmanifest_url = \"https://example.com/manifest.json\"\nstorage = DictBridgeStorage(\"user_id\")\n\nton_connect = TonConnect(manifest_url, storage)\n```\n\n### Connecting to a Wallet\n\nTo 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.\n\nYou can also use the `TonConnect.get_wallets` method to get a list of supported wallet apps.\n\n```python\nfrom ton_connect.model.app.wallet import WalletApp\nfrom ton_connect.connector import TonConnect\n\nwallets = await TonConnect.get_wallets()\nwallet = wallets[0]\n\nconnect_url = await ton_connect.connect(wallet)\nprint(\"Connect URL:\", connect_url)\n```\n\n### Restoring a Connection\n\nTo restore a connection to a wallet, you can use the `restore_connection` method. This method restores the connection using the stored connection data.\n\n```python\nawait ton_connect.restore_connection(wallet)\n```\n\n### Sending Requests\n\nThe `TonConnect` class provides methods to send various requests to the wallet. For example, you can send a transaction request using the `SendTransactionRequest` class.\n\n```python\nfrom ton_connect.model.app.request import SendTransactionRequest, SendTransactionMessage\n\nrequest = SendTransactionRequest(\n    address=\"0:1234567890abcdef\",\n    network=1,\n    messages=[\n        SendTransactionMessage(\n            address=\"0:abcdef1234567890\",\n            amount=\"1000000000\"\n        )\n    ]\n)\n\nresponse = await ton_connect.send(wallet.app_name, request)\nprint(\"Response:\", response)\n```\n\n### Listening for Wallet Events\n\nThe `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.\n\n```python\nfrom ton_connect.model.wallet.event import WalletEventName\nfrom ton_connect.connector import ConnectorEvent\n\nasync def on_connect(event: ConnectorEvent):\n    print(\"Connected:\", event)\n\nasync def on_disconnect(event: ConnectorEvent):\n    print(\"Disconnected:\", event)\n\nton_connect.listen(WalletEventName.CONNECT, on_connect)\nton_connect.listen(WalletEventName.DISCONNECT, on_disconnect)\n```\n\n## License\n\nThis project is licensed under the MIT License.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python SDK for TON Connect",
    "version": "0.2.18",
    "project_urls": {
        "Documentation": "https://github.com/yurzs/ton-connect",
        "Homepage": "https://github.com/yurzs/ton-connect"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8278f8a38105f66dafc6765c0fbabc55a2440dc7eb72ee3a34f55658f216e138",
                "md5": "8196493d947540cb91e5c98789b1191f",
                "sha256": "d0bde5992a00c3a6b5daf1050a253723e9494f7f51bcaba2ad303eca95299969"
            },
            "downloads": -1,
            "filename": "ton_connect_async-0.2.18-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8196493d947540cb91e5c98789b1191f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 22235,
            "upload_time": "2025-01-25T11:21:55",
            "upload_time_iso_8601": "2025-01-25T11:21:55.965120Z",
            "url": "https://files.pythonhosted.org/packages/82/78/f8a38105f66dafc6765c0fbabc55a2440dc7eb72ee3a34f55658f216e138/ton_connect_async-0.2.18-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "63c9d30142335f5183ccecf2038b53c791f1620121e7e697067faf44b436f144",
                "md5": "f236d64cfb8af5a9b42fff1c3081dcf6",
                "sha256": "2c70dfb4aa8e0a2639411b73fd3eb8b2df4ce408d861cb1b7bbbbb33a509cc5e"
            },
            "downloads": -1,
            "filename": "ton_connect_async-0.2.18.tar.gz",
            "has_sig": false,
            "md5_digest": "f236d64cfb8af5a9b42fff1c3081dcf6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 17047,
            "upload_time": "2025-01-25T11:21:58",
            "upload_time_iso_8601": "2025-01-25T11:21:58.536104Z",
            "url": "https://files.pythonhosted.org/packages/63/c9/d30142335f5183ccecf2038b53c791f1620121e7e697067faf44b436f144/ton_connect_async-0.2.18.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-25 11:21:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yurzs",
    "github_project": "ton-connect",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ton-connect-async"
}
        
Elapsed time: 1.18339s