Skip to main content

A Python API for interacting with the Tron (TRX)

https://img.shields.io/pypi/v/tronapi.svg https://img.shields.io/pypi/pyversions/tronapi.svg https://api.travis-ci.com/iexbase/tron-api-python.svg?branch=master https://img.shields.io/github/issues/iexbase/tron-api-python.svg https://img.shields.io/github/issues-pr/iexbase/tron-api-python.svg Codacy Badge

A Command-Line Interface framework

You can install it in a system-wide location via pip:

sudo pip3 install tronapi-JCO

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: TRWBqiqoFZysoAeyR1J35ibuyc8EvhUAoY

Release files for tronapi-JCO 3.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tronapi-JCO 3.2.3
File Size Uploaded
tronapi-JCO-3.2.3.tar.gz 45.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tronapi-JCO 3.2.3
File Interpreter ABI Platform
tronapi_JCO-3.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 98.1 kB

Release files / tronapi-JCO-3.2.3.tar.gz

Download URL tronapi-JCO-3.2.3.tar.gz
Size 45.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cf966f56b613490ac2fbe364fd1fbacbf6a4cf6c43a4810956fbd1fb24e56d89
BLAKE2b-256 checksum
How to use checksums
a98bb4fbc26a5f9cec1d101cd3f6385ac4dd2734b31cf4f0952623d4e75c489e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / tronapi_JCO-3.2.3-py3-none-any.whl

Download URL tronapi_JCO-3.2.3-py3-none-any.whl
Size 52.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
809cbe97301e1b65589d9919f95869e6c3b88752c99175de18938fb2cd95a7f2
BLAKE2b-256 checksum
How to use checksums
d394c43f25a1ed6124baa1ab70841ead8611056939234e9dd4a6e12e6e2d61e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

3.2.3 This release

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.2

2 release files

3.1.19

2 release files

3.1.18

2 release files

3.1.17

2 release files

3.1.16

2 release files

3.1.15

2 release files

3.1.14

2 release files

3.1.12

2 release files

3.1.11

2 release files

3.1.10

2 release files

3.1.9

2 release files

3.1.8

2 release files

3.1.7

2 release files

3.1.6

2 release files

3.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page