Skip to main content

TON Blockchain SDK

Project description

pytoniq

PyPI version PyPI - Python Version Downloads

Pytoniq is a Python SDK for the TON Blockchain. This library extends pytoniq-core with native LiteClient and ADNL over udp, DHT, RLDP (in future).

If you have any questions join Python - TON developers chat.

Documentation

GitBook

Installation

pip install pytoniq 

Examples

You can find them in the examples folder.

LiteClient

Blockstore

The library can prove all data it receives from a Liteserver (Learn about trust levels here). If you want to use LiteClient with the zero trust level, at the first time run library will prove block link from the init_block to the last masterchain block. Last proved blocks will be stored in the .blockstore folder. The file data contains ttl and gen_utime of the last synced key block, its data serialized according to the BlockIdExt TL scheme (but in big–endian), last synced masterchain block data. Filename is first 88 bytes of data described above with init block hash.

General LiteClient usage examples

Client initializing

from pytoniq import LiteClient


async def main():
    client = LiteClient.from_mainnet_config(  # choose mainnet, testnet or custom config dict
        ls_i=0,  # index of liteserver from config
        trust_level=2,  # trust level to liteserver
        timeout=15  # timeout not includes key blocks synchronization as it works in pytonlib
    )

    await client.connect()
    
    await client.reconnect()  # can reconnect to an exising object if had any errors

    await client.close()

Blocks transactions scanning

See BlockScanner code here.

from pytoniq_core import BlockIdExt
from pytoniq import LiteClient
from examples.blocks.block_scanner import BlockScanner  # this import is not available if downloaded from pypi

async def handle_block(block: BlockIdExt):
    if block.workchain == -1:  # skip masterchain blocks
        return
    print(block)
    transactions = await client.raw_get_block_transactions_ext(block)
    for transaction in transactions:
        print(transaction.in_msg)


client = LiteClient.from_mainnet_config(ls_i=14, trust_level=0, timeout=20)


async def main():

    await client.connect()
    await BlockScanner(client=client, block_handler=handle_block).run()

Project details


Download files

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

Source Distribution

pytoniq-0.1.2.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

pytoniq-0.1.2-py3-none-any.whl (230.5 kB view details)

Uploaded Python 3

File details

Details for the file pytoniq-0.1.2.tar.gz.

File metadata

  • Download URL: pytoniq-0.1.2.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pytoniq-0.1.2.tar.gz
Algorithm Hash digest
SHA256 64606102df1bf99190fcd1abd432b70d805ed6247468890977d3fa0c8b60132c
MD5 c0de2c30e755304624966a3a0de65ef2
BLAKE2b-256 63620d16c808fe64c08c6224a5a0008eec54ebe6627609381187758bcd73ae47

See more details on using hashes here.

File details

Details for the file pytoniq-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pytoniq-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 230.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pytoniq-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c90c3c8e12a3a67486a618662925bcfde095fd31f257f57574b443719853c24
MD5 968d0b3d95ae7805fa82b4606bb2a08d
BLAKE2b-256 765a1f9c2f15520a30a970fd78fc1c5bbd466b2989956460fbc0e4ede1308d3f

See more details on using hashes here.

Supported by

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