pytonconnect


Namepytonconnect JSON
Version 0.3.1 PyPI version JSON
download
home_pageNone
SummaryPython SDK for TON Connect 2.0
upload_time2024-04-16 19:15:19
maintainerNone
docs_urlNone
authorXaBbl4
requires_python>=3.7
licenseApache 2.0
keywords ton ton connect ton connect sdk
VCS
bugtrack_url
requirements PyNaCl httpx httpx-sse
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyTonConnect

[![PyPI](https://img.shields.io/pypi/v/pytonconnect?color=blue)](https://pypi.org/project/pytonconnect/)

Python SDK for TON Connect 2.0

Analogue of the [@tonconnect/sdk](https://github.com/ton-connect/sdk/tree/main/packages/sdk) library.

Use it to connect your app to TON wallets via TonConnect protocol. You can find more details and the protocol specification in the [docs](https://github.com/ton-connect/docs).

# Installation

Install Python 3 package: `pip3 install pytonconnect`

# Examples
## Add the tonconnect-manifest

App needs to have its manifest to pass meta information to the wallet. Manifest is a JSON file named as `tonconnect-manifest.json` following format:

```json
{
  "url": "<app-url>",                        // required
  "name": "<app-name>",                      // required
  "iconUrl": "<app-icon-url>",               // required
  "termsOfUseUrl": "<terms-of-use-url>",     // optional
  "privacyPolicyUrl": "<privacy-policy-url>" // optional
}
```

Make sure that manifest is available to GET by its URL.

## Init connector and call `restore_connection`.

If user connected his wallet before, connector will restore the connection

```python
import asyncio
from pytonconnect import TonConnect

async def main():
    connector = TonConnect(
        manifest_url='https://raw.githubusercontent.com/XaBbl4/pytonconnect/main/pytonconnect-manifest.json',
        # api_tokens={'tonapi': 'key'},
    )
    is_connected = await connector.restore_connection()
    print('is_connected:', is_connected)

if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(main())
```

## Fetch wallets list

You can fetch all supported wallets list

```python
wallets_list = connector.get_wallets()

# wallets_list is 
# [
#   {
#     name: str,
#     image: str,
#     about_url: str,
#     bridge_url: str,
#     universal_url: str,
#   },
# ]
```

You also can get wallets list using `get_wallets` static method:
```python
wallets_list = TonConnect.get_wallets()
```

## Subscribe to the connection status changes

```python
def status_changed(wallet_info):
    # update state/reactive variables to show updates in the ui
    print('wallet_info:', wallet_info)
    unsubscribe()

unsubscribe = connector.on_status_change(status_changed)
# call unsubscribe() later to save resources when you don't need to listen for updates anymore.
```

## Initialize a wallet connection via universal link
```python
generated_url = await connector.connect(wallets_list[0])
print('generated_url:', generated_url)
```

Then you have to show this link to user as QR-code, or use it as a deep_link. You will receive an update in `connector.on_status_change` when user approves connection in the wallet.

## Send transaction

```python
transaction = {
    'valid_until': 1681223913,
    'messages': [
        {
            'address': '0:0000000000000000000000000000000000000000000000000000000000000000',
            'amount': '1',
            # 'stateInit': 'base64_YOUR_STATE_INIT' # just for instance. Replace with your transaction state_init or remove
        },
        {
            'address': '0:0000000000000000000000000000000000000000000000000000000000000000',
            'amount': '1',
            # 'payload': 'base64_YOUR_PAYLOAD' # just for instance. Replace with your transaction payload or remove
        }
    ]
}

try:
    result = await connector.send_transaction(transaction)
    print('Transaction was sent successfully')
except Exception as e:
    if isintance(e, UserRejectsError):
        print('You rejected the transaction. Please confirm it to send to the blockchain')
    else:
        print('Unknown error:', e)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytonconnect",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "TON, TON Connect, TON Connect SDK",
    "author": "XaBbl4",
    "author_email": "xabbl4@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6c/f0/2029a9ecfea3f15aab5f8b56817f24f0ff9f8162de6f9f967e4ab44bc65a/pytonconnect-0.3.1.tar.gz",
    "platform": null,
    "description": "# PyTonConnect\r\n\r\n[![PyPI](https://img.shields.io/pypi/v/pytonconnect?color=blue)](https://pypi.org/project/pytonconnect/)\r\n\r\nPython SDK for TON Connect 2.0\r\n\r\nAnalogue of the [@tonconnect/sdk](https://github.com/ton-connect/sdk/tree/main/packages/sdk) library.\r\n\r\nUse it to connect your app to TON wallets via TonConnect protocol. You can find more details and the protocol specification in the [docs](https://github.com/ton-connect/docs).\r\n\r\n# Installation\r\n\r\nInstall Python 3 package: `pip3 install pytonconnect`\r\n\r\n# Examples\r\n## Add the tonconnect-manifest\r\n\r\nApp needs to have its manifest to pass meta information to the wallet. Manifest is a JSON file named as `tonconnect-manifest.json` following format:\r\n\r\n```json\r\n{\r\n  \"url\": \"<app-url>\",                        // required\r\n  \"name\": \"<app-name>\",                      // required\r\n  \"iconUrl\": \"<app-icon-url>\",               // required\r\n  \"termsOfUseUrl\": \"<terms-of-use-url>\",     // optional\r\n  \"privacyPolicyUrl\": \"<privacy-policy-url>\" // optional\r\n}\r\n```\r\n\r\nMake sure that manifest is available to GET by its URL.\r\n\r\n## Init connector and call `restore_connection`.\r\n\r\nIf user connected his wallet before, connector will restore the connection\r\n\r\n```python\r\nimport asyncio\r\nfrom pytonconnect import TonConnect\r\n\r\nasync def main():\r\n    connector = TonConnect(\r\n        manifest_url='https://raw.githubusercontent.com/XaBbl4/pytonconnect/main/pytonconnect-manifest.json',\r\n        # api_tokens={'tonapi': 'key'},\r\n    )\r\n    is_connected = await connector.restore_connection()\r\n    print('is_connected:', is_connected)\r\n\r\nif __name__ == '__main__':\r\n    asyncio.get_event_loop().run_until_complete(main())\r\n```\r\n\r\n## Fetch wallets list\r\n\r\nYou can fetch all supported wallets list\r\n\r\n```python\r\nwallets_list = connector.get_wallets()\r\n\r\n# wallets_list is \r\n# [\r\n#   {\r\n#     name: str,\r\n#     image: str,\r\n#     about_url: str,\r\n#     bridge_url: str,\r\n#     universal_url: str,\r\n#   },\r\n# ]\r\n```\r\n\r\nYou also can get wallets list using `get_wallets` static method:\r\n```python\r\nwallets_list = TonConnect.get_wallets()\r\n```\r\n\r\n## Subscribe to the connection status changes\r\n\r\n```python\r\ndef status_changed(wallet_info):\r\n    # update state/reactive variables to show updates in the ui\r\n    print('wallet_info:', wallet_info)\r\n    unsubscribe()\r\n\r\nunsubscribe = connector.on_status_change(status_changed)\r\n# call unsubscribe() later to save resources when you don't need to listen for updates anymore.\r\n```\r\n\r\n## Initialize a wallet connection via universal link\r\n```python\r\ngenerated_url = await connector.connect(wallets_list[0])\r\nprint('generated_url:', generated_url)\r\n```\r\n\r\nThen you have to show this link to user as QR-code, or use it as a deep_link. You will receive an update in `connector.on_status_change` when user approves connection in the wallet.\r\n\r\n## Send transaction\r\n\r\n```python\r\ntransaction = {\r\n    'valid_until': 1681223913,\r\n    'messages': [\r\n        {\r\n            'address': '0:0000000000000000000000000000000000000000000000000000000000000000',\r\n            'amount': '1',\r\n            # 'stateInit': 'base64_YOUR_STATE_INIT' # just for instance. Replace with your transaction state_init or remove\r\n        },\r\n        {\r\n            'address': '0:0000000000000000000000000000000000000000000000000000000000000000',\r\n            'amount': '1',\r\n            # 'payload': 'base64_YOUR_PAYLOAD' # just for instance. Replace with your transaction payload or remove\r\n        }\r\n    ]\r\n}\r\n\r\ntry:\r\n    result = await connector.send_transaction(transaction)\r\n    print('Transaction was sent successfully')\r\nexcept Exception as e:\r\n    if isintance(e, UserRejectsError):\r\n        print('You rejected the transaction. Please confirm it to send to the blockchain')\r\n    else:\r\n        print('Unknown error:', e)\r\n```\r\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "Python SDK for TON Connect 2.0",
    "version": "0.3.1",
    "project_urls": {
        "Github": "https://github.com/XaBbl4/pytonconnect"
    },
    "split_keywords": [
        "ton",
        " ton connect",
        " ton connect sdk"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "979198cdf5124ae37ee61c73c81a48de2cf0a04a399ba17da4028db33159563d",
                "md5": "55ba948b26fd7e6668c61bbded64e484",
                "sha256": "44f1dcd711f17e2069f6c40cbc137f93e1d78623704b091f5c7b5c44c76373d6"
            },
            "downloads": -1,
            "filename": "pytonconnect-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "55ba948b26fd7e6668c61bbded64e484",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 24727,
            "upload_time": "2024-04-16T19:15:17",
            "upload_time_iso_8601": "2024-04-16T19:15:17.909765Z",
            "url": "https://files.pythonhosted.org/packages/97/91/98cdf5124ae37ee61c73c81a48de2cf0a04a399ba17da4028db33159563d/pytonconnect-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6cf02029a9ecfea3f15aab5f8b56817f24f0ff9f8162de6f9f967e4ab44bc65a",
                "md5": "1fe0afacae0f120fc7fcdd78facd294d",
                "sha256": "ef9e9b07264c0ca72eb751dc47f6b3a8d42f452fa1db9e786a04ca6d76884c38"
            },
            "downloads": -1,
            "filename": "pytonconnect-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1fe0afacae0f120fc7fcdd78facd294d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 20713,
            "upload_time": "2024-04-16T19:15:19",
            "upload_time_iso_8601": "2024-04-16T19:15:19.760118Z",
            "url": "https://files.pythonhosted.org/packages/6c/f0/2029a9ecfea3f15aab5f8b56817f24f0ff9f8162de6f9f967e4ab44bc65a/pytonconnect-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-16 19:15:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "XaBbl4",
    "github_project": "pytonconnect",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "PyNaCl",
            "specs": []
        },
        {
            "name": "httpx",
            "specs": []
        },
        {
            "name": "httpx-sse",
            "specs": []
        }
    ],
    "lcname": "pytonconnect"
}
        
Elapsed time: 0.32275s