Skip to main content

A Python API for interacting with Tron (TRX)

Project description

A Python API for interacting with the Tron (TRX)

https://img.shields.io/pypi/v/tronpytool.svg https://img.shields.io/pypi/pyversions/tronpytool.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 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 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 tronpytool 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

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.1.tar.gz (54.1 kB view details)

Uploaded Source

Built Distribution

tronpytool-3.3.1-py3-none-any.whl (62.6 kB view details)

Uploaded Python 3

File details

Details for the file tronpytool-3.3.1.tar.gz.

File metadata

  • Download URL: tronpytool-3.3.1.tar.gz
  • Upload date:
  • Size: 54.1 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

Hashes for tronpytool-3.3.1.tar.gz
Algorithm Hash digest
SHA256 8ecc23403732f6a7d56afad5d7f28d342269f186dc5685c9df82f75ae85f8689
MD5 5c3112240c10f020570bb2aa075dabea
BLAKE2b-256 2e84bfac1b2ae9a7f63034bd4ca0f7fdb6ff0e5258356b5314b71068bcec58fd

See more details on using hashes here.

File details

Details for the file tronpytool-3.3.1-py3-none-any.whl.

File metadata

  • Download URL: tronpytool-3.3.1-py3-none-any.whl
  • Upload date:
  • Size: 62.6 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

Hashes for tronpytool-3.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dae28b4c8597a4413b6efb0fe2e9f8b100156e30b9053438683b5e681f16742
MD5 78433b9967907490911cfc385828d6ce
BLAKE2b-256 2974b87f02b26b893dc95d3c42759aa80b57809dac92ca4eac852f18bd129313

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page