A Python API for interacting with the Tron (TRX)
Setup | Command | Notes |
---|---|---|
install | pip install tronapi |
Specify the API endpoints:
full_node = HttpProvider('https://api.trongrid.io')
solidity_node = HttpProvider('https://api.trongrid.io')
event_server = HttpProvider('https://api.trongrid.io')
The provider above is optional, you can just use a url for the nodes instead, like here:
full_node = 'https://api.trongrid.io'
solidity_node = 'https://api.trongrid.io'
event_server = 'https://api.trongrid.io'
Now, instance a Tron class:
private_key = '....'
tron = Tron(full_node,
solidity_node,
event_server,
private_key)
A full example:
from tronapi.provider import HttpProvider
from tronapi.tron import Tron
full_node = HttpProvider('https://api.trongrid.io')
solidity_node = HttpProvider('https://api.trongrid.io')
event_server = HttpProvider('https://api.trongrid.io')
# optional
private_key = '...'
tron = Tron(full_node,
solidity_node,
event_server,
private_key)
block = tron.get_current_block()
balance = tron.get_balance('TRWBqiqoFZysoAeyR1J35ibuyc8EvhUAoY', True)
> python cli.py send from to amount private_key
> python cli.py --generateaddress
> python cli.py --node=customnode --getbalance address
Tron(TRX): TRWBqiqoFZysoAeyR1J35ibuyc8EvhUAoY