pytonconnect-fixed


Namepytonconnect-fixed JSON
Version 0.3.1 PyPI version JSON
download
home_pageNone
SummaryPython SDK for TON Connect 2.0
upload_time2024-12-01 19:49:59
maintainerNone
docs_urlNone
authorXaBbl4
requires_python>=3.7
licenseApache 2.0
keywords ton ton connect ton connect sdk
VCS
bugtrack_url
requirements No requirements were recorded.
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-fixed",
    "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/c5/0b/eaec035ca20cb1e6984221a45822fc6d74b5d84e5df43a50dc0c291b943d/pytonconnect_fixed-0.3.1.tar.gz",
    "platform": null,
    "description": "# PyTonConnect\n\n[![PyPI](https://img.shields.io/pypi/v/pytonconnect?color=blue)](https://pypi.org/project/pytonconnect/)\n\nPython SDK for TON Connect 2.0\n\nAnalogue of the [@tonconnect/sdk](https://github.com/ton-connect/sdk/tree/main/packages/sdk) library.\n\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).\n\n# Installation\n\nInstall Python 3 package: `pip3 install pytonconnect`\n\n# Examples\n## Add the tonconnect-manifest\n\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:\n\n```json\n{\n  \"url\": \"<app-url>\",                        // required\n  \"name\": \"<app-name>\",                      // required\n  \"iconUrl\": \"<app-icon-url>\",               // required\n  \"termsOfUseUrl\": \"<terms-of-use-url>\",     // optional\n  \"privacyPolicyUrl\": \"<privacy-policy-url>\" // optional\n}\n```\n\nMake sure that manifest is available to GET by its URL.\n\n## Init connector and call `restore_connection`.\n\nIf user connected his wallet before, connector will restore the connection\n\n```python\nimport asyncio\nfrom pytonconnect import TonConnect\n\nasync def main():\n    connector = TonConnect(\n        manifest_url='https://raw.githubusercontent.com/XaBbl4/pytonconnect/main/pytonconnect-manifest.json',\n        # api_tokens={'tonapi': 'key'},\n    )\n    is_connected = await connector.restore_connection()\n    print('is_connected:', is_connected)\n\nif __name__ == '__main__':\n    asyncio.get_event_loop().run_until_complete(main())\n```\n\n## Fetch wallets list\n\nYou can fetch all supported wallets list\n\n```python\nwallets_list = connector.get_wallets()\n\n# wallets_list is \n# [\n#   {\n#     name: str,\n#     image: str,\n#     about_url: str,\n#     bridge_url: str,\n#     universal_url: str,\n#   },\n# ]\n```\n\nYou also can get wallets list using `get_wallets` static method:\n```python\nwallets_list = TonConnect.get_wallets()\n```\n\n## Subscribe to the connection status changes\n\n```python\ndef status_changed(wallet_info):\n    # update state/reactive variables to show updates in the ui\n    print('wallet_info:', wallet_info)\n    unsubscribe()\n\nunsubscribe = connector.on_status_change(status_changed)\n# call unsubscribe() later to save resources when you don't need to listen for updates anymore.\n```\n\n## Initialize a wallet connection via universal link\n```python\ngenerated_url = await connector.connect(wallets_list[0])\nprint('generated_url:', generated_url)\n```\n\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.\n\n## Send transaction\n\n```python\ntransaction = {\n    'valid_until': 1681223913,\n    'messages': [\n        {\n            'address': '0:0000000000000000000000000000000000000000000000000000000000000000',\n            'amount': '1',\n            # 'stateInit': 'base64_YOUR_STATE_INIT' # just for instance. Replace with your transaction state_init or remove\n        },\n        {\n            'address': '0:0000000000000000000000000000000000000000000000000000000000000000',\n            'amount': '1',\n            # 'payload': 'base64_YOUR_PAYLOAD' # just for instance. Replace with your transaction payload or remove\n        }\n    ]\n}\n\ntry:\n    result = await connector.send_transaction(transaction)\n    print('Transaction was sent successfully')\nexcept Exception as e:\n    if isintance(e, UserRejectsError):\n        print('You rejected the transaction. Please confirm it to send to the blockchain')\n    else:\n        print('Unknown error:', e)\n```\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": "ab0af52c864495a82ad8d372d239fff302bb9b3d8d3c5e836293b968f0acb559",
                "md5": "f21bbb2db98acfeca2f445df8cc7e3e6",
                "sha256": "96a73963430fd4a196cb19174a449961c8225474d3909de2ffd0bb0f4c6b2558"
            },
            "downloads": -1,
            "filename": "pytonconnect_fixed-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f21bbb2db98acfeca2f445df8cc7e3e6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 24217,
            "upload_time": "2024-12-01T19:49:57",
            "upload_time_iso_8601": "2024-12-01T19:49:57.743070Z",
            "url": "https://files.pythonhosted.org/packages/ab/0a/f52c864495a82ad8d372d239fff302bb9b3d8d3c5e836293b968f0acb559/pytonconnect_fixed-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c50beaec035ca20cb1e6984221a45822fc6d74b5d84e5df43a50dc0c291b943d",
                "md5": "e77ff243d53f9aa711f8b781ec5c0c94",
                "sha256": "7fb7bf35124015ea91e912b8f391e51e9361e593efdd90240fa8932413f36678"
            },
            "downloads": -1,
            "filename": "pytonconnect_fixed-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e77ff243d53f9aa711f8b781ec5c0c94",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 20040,
            "upload_time": "2024-12-01T19:49:59",
            "upload_time_iso_8601": "2024-12-01T19:49:59.552996Z",
            "url": "https://files.pythonhosted.org/packages/c5/0b/eaec035ca20cb1e6984221a45822fc6d74b5d84e5df43a50dc0c291b943d/pytonconnect_fixed-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-01 19:49:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "XaBbl4",
    "github_project": "pytonconnect",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "pytonconnect-fixed"
}
        
Elapsed time: 0.83389s