Skip to main content

Native library for working with TON (The Open Network)

Project description

What is it?

This is a native library for working with The Open Network - without using libtonlibjson.so. But for nativeness, we have to pay with speed. This library was written based on this documentation: https://github.com/xssnick/ton-deep-doc

Installation

pip3 install mytonlib

How to use

from mytonlib import AdnlTcpClientWithBalancer

global_config_url = "https://ton-blockchain.github.io/global.config.json"
adnl = AdnlTcpClientWithBalancer(global_config_url)

# Get masterchain info
adnl.get_masterchain_info()

How to use without balancer

from mytonlib import AdnlTcpClient

# Take public lite-server from https://ton-blockchain.github.io/global.config.json
host = "185.86.79.9"
port = 4701
pubkey = "G6cNAr6wXBBByWDzddEWP5xMFsAcp6y13fXA8Q7EJlM="

# Connect to the lite-server with adnl
adnl = AdnlTcpClient()
adnl.connect(host, port, pubkey)

# Test connection
adnl.ping()

# Get masterchain info
adnl.get_masterchain_info()

List of available functions

All available functions are taken from lite-client

connect 				# Connect to the lite-server with adnl
ping 					# Test connection
get_time 				# Get server time
get_masterchain_info 	# Get last block and state info from server
get_account_state		# Loads the most recent state of specified account
run_smc_method			# Runs GET method <method-id> of account <addr> with specified parameters
get_all_shards_info		# Shows shard configuration from the most recent masterchain state or from masterchain state corresponding to <block-id-ext>
get_config_params		# Shows specified or all configuration parameters from the latest masterchain state
get_block_header		# Shows block header for <block-id-ext>
get_block				# Downloads block
get_last_transactions	# Shows or dumps specified transaction and several preceding ones
get_block_transactions	# Lists block transactions, starting immediately after or before the specified one
get_one_transaction		# Dumps one transaction of specified account
lookup_block			# Looks up a block by workchain, shard and seqno/lt/time, and shows its header

TLB unpacking

A feature of this library is the automatic unpacking of data according to the TLB scheme:

from mytonlib import TlbSchemes

tlb_schemes = TlbSchemes()
tlb_schemes.load_schemes("/usr/src/ton/tl/generate/scheme/")

data = adnl.run_smc_method("kQBL2_3lMiyywU17g-or8N7v9hDmPCpttzBPE2isF2GTziky", "mult", [5, 4])
print(data) # or print(json.dumps(data, indent=4))

tlb_schemes.load_schemes_from_text("mycell$_ value:uint64 = MyCell;")
data = tlb_schemes.deserialize(data, expected="MyCell")
print(data.value)

More examples

https://github.com/igroman787/mytonlib/blob/master/mytonlib/tests.py

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

mytonlib-0.7.4.tar.gz (58.5 kB view details)

Uploaded Source

File details

Details for the file mytonlib-0.7.4.tar.gz.

File metadata

  • Download URL: mytonlib-0.7.4.tar.gz
  • Upload date:
  • Size: 58.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for mytonlib-0.7.4.tar.gz
Algorithm Hash digest
SHA256 88b4574db2e1aafa86f28969995844105d30ec92a34431565211ff68851e7245
MD5 9d7ad095b6522bac6410eb55c99acee5
BLAKE2b-256 fa34f179590eaa47558a6715f9bec4cb22b600ab8f31998ce8e6e67301e21ff7

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