A Python API for interacting with Tron (TRX)
Project description
A Python API for interacting with the Tron (TRX)
A Command-Line Interface framework
You can install it in a system-wide location via pip:
sudo pip3 install tronpytool
Or install it locally using virtualenv:
virtualenv -p /usr/bin/python3 ~/tronpytool
source ~/tronpytool/bin/activate
pip3 install tronpytool
Usage
Specify the API endpoints:
Smart Contract
from tronpytool import HttpProvider
from tronpytool import Tron
full_node = HttpProvider('https://api.trongrid.io')
solidity_node = HttpProvider('https://api.trongrid.io')
event_server = HttpProvider('https://api.trongrid.io')
# option 1
tron = Tron(full_node=full_node,
solidity_node=solidity_node,
event_server=event_server)
# option 2
tron_v2 = Tron()
# option 3
tron_v3 = Tron(
default_address='TRWBqiqoFZysoAeyR1J35ibuyc8EvhUAoY',
private_key='...'
)
# option 4
tron_v4 = Tron().setNetwork('nile')
Base Example
from tronpytool import Tron
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger()
tron = Tron().setNetwork("nile")
account = tron.create_account()
is_valid = bool(tron.trx.is_address(account.address.hex))
logger.debug('Generated account: ')
logger.debug('- Private Key: ' + account.private_key)
logger.debug('- Public Key: ' + account.public_key)
logger.debug('- Address: ')
logger.debug('-- Base58: ' + account.address.base58)
logger.debug('-- Hex: ' + account.address.hex)
logger.debug('-- isValid: ' + str(is_valid))
logger.debug('-----------')
transaction = tron.trx.get_transaction('757a14cef293c69b1cf9b9d3d19c2e40a330c640b05c6ffa4d54609a9628758c')
logger.debug('Transaction: ')
logger.debug('- Hash: ' + transaction['txID'])
logger.debug('- Transaction: ' + json.dumps(transaction, indent=2))
logger.debug('-----------')
# Events
event_result = tron.trx.get_event_result('TGEJj8eus46QMHPgWQe1FJ2ymBXRm96fn1', 0, 'Notify')
logger.debug('Event result:')
logger.debug('Contract Address: TGEJj8eus46QMHPgWQe1FJ2ymBXRm96fn1')
logger.debug('Event Name: Notify')
logger.debug('Block Number: 32162')
logger.debug('- Events: ' + json.dumps(event_result, indent=2))
More samples and snippets are available at examples.
Documentation
Documentation is available at docs.
Donations
TRON: TRWBqiqoFZysoAeyR1J35ibuyc8EvhUAoY
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
tronpytool-3.3.45.tar.gz
(54.9 kB
view details)
Built Distribution
File details
Details for the file tronpytool-3.3.45.tar.gz
.
File metadata
- Download URL: tronpytool-3.3.45.tar.gz
- Upload date:
- Size: 54.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1307840dec18c0df78f28215fdae80e04034c947b0d34634991d4a49218f39b6 |
|
MD5 | 6d37949cf5d71dcf9f0bb8cde62b6d72 |
|
BLAKE2b-256 | f361b322d5f3a2ac91ac4d8eb183cf91e226432adf6cb741b29139fa9bce7837 |
File details
Details for the file tronpytool-3.3.45-py3-none-any.whl
.
File metadata
- Download URL: tronpytool-3.3.45-py3-none-any.whl
- Upload date:
- Size: 63.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82d1cea1efceb9203a2a4c7997193bc550f136e03cf81172cb6472a852f33776 |
|
MD5 | f3b791d427b3d3ba897d91f8a11736bf |
|
BLAKE2b-256 | 1721cad63c5bf38fb64d8740d43e054b19f37e2279ee0f076eee7b80acf27604 |