How to Create Tron Address & Private Key in Python

PyMmdrza
3 min readFeb 28, 2023

--

Generated tron (trx) address from private key hex in python

TRON is a decentralized blockchain-based platform that aims to create a global digital content entertainment system. It allows developers to create and deploy decentralized applications (dapps) on its network. TRON uses a consensus mechanism called delegated proof-of-stake (DPoS), where token holders elect “super representatives” to validate transactions and create new blocks.

How to Generated Private Key TRON TRX In Python and Address
TRON TRX Private Key Generated Address

TRON’s native cryptocurrency is called TRX, which is used to pay for transactions and services on the TRON network. TRX can be bought and sold on various cryptocurrency exchanges.

TRON addresses are used to send and receive TRX tokens on the TRON network. TRON addresses are similar to Ethereum addresses in format and are represented as 42-character strings starting with the letter “T”. TRON addresses are generated from a private key using a specific algorithm. It is important to keep your private keys secure and never share them with anyone. If someone has access to your private key, they can transfer your TRX tokens to their own address. There are various ways to store private keys securely, including hardware wallets and paper wallets.

In summary, TRON is a decentralized blockchain-based platform that uses TRX as its native cryptocurrency. TRON addresses are used to send and receive TRX tokens, and private keys are used to sign transactions and prove ownership of TRX tokens.

To generate a Tron address from a hex in Python, you can use the following steps:

  1. Import the necessary modules: binascii and base58.
  2. Convert the hex string to bytes using binascii.unhexlify().
  3. Prepend the bytes with b"\x41".
  4. Take the SHA3–256 hash of the bytes using hashlib.sha3_256().
  5. Take the last 20 bytes of the hash.
  6. Prepend the bytes with b"\x41".
  7. Encode the bytes using base58.b58encode_check().

Here is the code to generate a Tron address from a hex in Python:

pip install base58
pip install ecdsa
pip install cryptodome
import base58, ecdsa
from Crypto.Hash import keccak


def hex_to_TRON_ADDR(key_string):

keybytes = bytes.fromhex(key_string)

sk = ecdsa.SigningKey.from_string(keybytes, curve=ecdsa.SECP256k1)
key = sk.get_verifying_key()
KEY = key.to_string()
Keccak = keccak.new(digest_bits=256)
Keccak.update(KEY)
pub_key = Keccak.digest()
primitive_addr = b'\x41' + pub_key[-20:]
# 0 (zero), O (capital o), I (capital i) and l (lower case L)
addr = base58.b58encode_check(primitive_addr)
return addr.decode()

You can use this function by passing a hex string to it, like this:

hex_string = "7f16aa2dce8a6d00e50d0960b5b949139b8e647d58"
address = hex_to_TRON_ADDR(hex_string)
print(address)

--

--