TRON Python client library
Project description
tronpy
TRON Python Client Library. Documentation
How to use
from tronpy23 import Tron
from tronpy23.keys import PrivateKey
client = Tron(network='nile')
# Private key of TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3
priv_key = PrivateKey(bytes.fromhex("8888888888888888888888888888888888888888888888888888888888888888"))
txn = (
client.trx.transfer("TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3", "TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA", 1_000)
.memo("test memo")
.build()
.inspect()
.sign(priv_key)
.broadcast()
)
print(txn)
# > {'result': True, 'txid': '5182b96bc0d74f416d6ba8e22380e5920d8627f8fb5ef5a6a11d4df030459132'}
print(txn.wait())
# > {'id': '5182b96bc0d74f416d6ba8e22380e5920d8627f8fb5ef5a6a11d4df030459132', 'blockNumber': 6415370, 'blockTimeStamp': 1591951155000, 'contractResult': [''], 'receipt': {'net_usage': 283}}
Async Client
import asyncio
from tronpy23 import AsyncTron
from tronpy23.keys import PrivateKey
# private key of TMisHYBVvFHwKXHPYTqo8DhrRPTbWeAM6z
priv_key = PrivateKey(bytes.fromhex("8888888888888888888888888888888888888888888888888888888888888888"))
async def transfer():
async with AsyncTron(network='nile') as client:
print(client)
txb = (
client.trx.transfer("TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3", "TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA", 1_000)
.memo("test memo")
.fee_limit(100_000_000)
)
txn = await txb.build()
print(txn)
txn_ret = await txn.sign(priv_key).broadcast()
print(txn_ret)
# > {'result': True, 'txid': 'edc2a625752b9c71fdd0d68117802860c6adb1a45c19fd631a41757fa334d72b'}
print(await txn_ret.wait())
# > {'id': 'edc2a625752b9c71fdd0d68117802860c6adb1a45c19fd631a41757fa334d72b', 'blockNumber': 10163821, 'blockTimeStamp': 1603368072000, 'contractResult': [''], 'receipt': {'net_usage': 283}}
if __name__ == '__main__':
asyncio.run(transfer())
Or close async client manually:
from httpx import AsyncClient, Timeout
from tronpy23.providers.async_http import AsyncHTTPProvider
from tronpy23.defaults import CONF_NILE
async def transfer():
_http_client = AsyncClient(limits=Limits(max_connections=100, max_keepalive_connections=20),
timeout=Timeout(timeout=10, connect=5, read=5))
provider = AsyncHTTPProvider(CONF_NILE, client=_http_client)
client = AsyncTron(provider=provider)
print(client)
priv_key = PrivateKey(bytes.fromhex("8888888888888888888888888888888888888888888888888888888888888888"))
txb = (
client.trx.transfer("TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3", "TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA", 1_000)
.memo("test memo")
.fee_limit(100_000_000)
)
txn = await txb.build()
print(txn)
txn_ret = await txn.sign(priv_key).broadcast()
print(txn_ret)
print(await txn_ret.wait())
await client.close()
if __name__ == '__main__':
asyncio.run(transfer())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tronpy23-0.1.0.tar.gz
(31.9 kB
view details)
Built Distribution
tronpy23-0.1.0-py3-none-any.whl
(34.1 kB
view details)
File details
Details for the file tronpy23-0.1.0.tar.gz
.
File metadata
- Download URL: tronpy23-0.1.0.tar.gz
- Upload date:
- Size: 31.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4457094e533663031d7599ebeff1ada087b478c647f1f29377320cb6acd4017b |
|
MD5 | 8a62da5fa112c62dab5712f3bd7c21d8 |
|
BLAKE2b-256 | 5e13f20f2efe94a56d3864e757d40320d612de7b9530e5425c77127e20533809 |
File details
Details for the file tronpy23-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: tronpy23-0.1.0-py3-none-any.whl
- Upload date:
- Size: 34.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e629dee1825678214275a32a314b4e684651a903f1d46a36a3f538fe29aae5a |
|
MD5 | 251256a8d53b0175975b053a072586ab |
|
BLAKE2b-256 | a3e72ac54ede0270b056f173987a5eaaf2b60d0177752b4dc9a193f629548309 |