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 tronapi
Or install it locally using virtualenv:
virtualenv -p /usr/bin/python3 ~/tronapi
source ~/tronapi/bin/activate
pip3 install tronapi
Usage
Specify the API endpoints:
Smart Contract
from tronapi import Tron
from solc import compile_source
full_node = 'https://api.trongrid.io'
solidity_node = 'https://api.trongrid.io'
event_server = 'https://api.trongrid.io'
tron = Tron(full_node=full_node,
solidity_node=solidity_node,
event_server=event_server)
# or default (tron = Tron())
# Solidity source code
contract_source_code = '''
pragma solidity ^0.4.25;
contract Hello {
string public message;
function Hello(string initialMessage) public {
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}
'''
compiled_sol = compile_source(contract_source_code)
contract_interface = compiled_sol['<stdin>:Hello']
hello = tron.trx.contract(
abi=contract_interface['abi'],
bytecode=contract_interface['bin']
)
# Submit the transaction that deploys the contract
tx = hello.deploy(
fee_limit=10**9,
call_value=0,
consume_user_resource_percent=1
)
Base Example
from tronapi import Tron
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger()
full_node = 'https://api.trongrid.io'
solidity_node = 'https://api.trongrid.io'
event_server = 'https://api.trongrid.io'
tron = Tron(full_node=full_node,
solidity_node=solidity_node,
event_server=event_server)
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: TQ2386PsHYHQSYqLJd5RHSV2T6iVxHqy5e
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tronweb-3.1.5.1.tar.gz.
File metadata
- Download URL: tronweb-3.1.5.1.tar.gz
- Upload date:
- Size: 44.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c62334a1d3537e9d7c25515c9b7294a8911a6bf4f84e65c8e20c30ec604f139
|
|
| MD5 |
e26ac1c73951792c80f5e5376d63897c
|
|
| BLAKE2b-256 |
01cb16708250f7a1b29a7e5a20c03cbd4d2b219d26144accd62c42380bc4b995
|
File details
Details for the file tronweb-3.1.5.1-py3-none-any.whl.
File metadata
- Download URL: tronweb-3.1.5.1-py3-none-any.whl
- Upload date:
- Size: 50.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d13d744de6f18bd52c7606613a517450951a06ea56578424ef59eb9a185574e
|
|
| MD5 |
f410251b70dfb64db46fa50b4cd24803
|
|
| BLAKE2b-256 |
efcc4bc703852b41b9e0fdd6aa06c4fd0f15a50b5f1483b06f9e1a147ff35df7
|