Running a Tron transaction via python PyTron

Tronpy is a Python library designed for interacting with the TRON blockchain. It provides a convenient interface for developers to work with TRON's features and functionalities.

To use Tronpy, you need to install it via pip:

pip install tronpy

Some of the key features of Tronpy include:

  • Transaction Handling: You can create, sign, and broadcast transactions on the TRON network.
  • Smart Contract Interaction: It supports interacting with smart contracts deployed on the TRON blockchain.
  • Account Management: It allows you to generate new accounts, manage private keys, and handle TRON addresses.
  • Blockchain Queries: You can query the TRON blockchain for information such as account balances, transaction history, and contract details.

Here's a basic example of using Tronpy to send TRX:

from tronpy import Tron
from tronpy.keys import PrivateKey

# Initialize Tron client for the mainnet or testnet
client = Tron()

# Define sender and recipient addresses
sender_address = 'T...your_sender_address'
recipient_address = 'T...recipient_address'

# Define the amount to transfer (in sun, where 1 TRX = 1,000,000 sun)
amount = 1_000_000  # 1 TRX in sun

# Define the sender's private key
sender_private_key = PrivateKey(bytes.fromhex('your_private_key_here'))

# Create, sign, and broadcast the transaction with a memo
txn = (
    client.trx.transfer(sender_address, recipient_address, amount)
    .memo("test memo")
    .build()
    .sign(sender_private_key)
    .broadcast()
)

# Print transaction result
print(txn)
python
tron
tronpy
Software and digital electronics / Coding
Posted by Neizer
2024-07-29 03:23
×

Login

No account?
Terms of use
Forgot password?