TRC20 address introduction
The TRC20 address is a digital wallet address used to receive or send Tether cryptocurrencies. Each TRC20 address consists of a set of 26 to 64 characters, usually starting with 0x, followed by a series of capital letters and numbers. If you want to trade with a TRC20 address, you need to provide it to a digital currency exchange or other trading platform and follow the instructions.
Python calculates TRC20 address
Complete code
import hashlib from eth_utils import keccak import base58 import ecdsa from import PrivateKey def test1(): # Sample private key, replace with your own private key private_key_hex = "your_private_key_hex_string" # Convert hexadecimal private key to byte form private_key_bytes = (private_key_hex) # Use SECP256k1 curve to generate private key objects sk = .from_string(private_key_bytes, curve=ecdsa.SECP256k1) # Deriving a public key from a private key vk = sk.get_verifying_key() public_key_bytes = vk.to_string() public_key_point = # Hash the public key using Keccak-256 public_key_hash = keccak(public_key_bytes) # Take the last 20 bytes of the hash and prepend 0x41 # Add TRON address prefix (0x41) tron_prefix = b'\x41' prefixed_hash160 = tron_prefix + public_key_hash[-20:] # SHA-256 hash the result after adding the prefix to get the checksum first_sha256 = hashlib.sha256(prefixed_hash160).digest() second_sha256 = hashlib.sha256(first_sha256).digest() # Take the first 4 bytes as checksum checksum = second_sha256[:4] # Splice prefix, hash results, and checksum full_payload = prefixed_hash160 + checksum # Convert to hexadecimal string trc_address_hex = prefixed_hash160.hex() # Use Base58 encoding to generate the final TRC address trc_address = base58.b58encode(full_payload).decode() # Print private key (in hexadecimal string) print("Private key (hexadecimal):", sk.to_string().hex()) # Print public key (in hexadecimal string) print("Public Key (hexadecimal):", vk.to_string().hex()) # Print the points on the elliptic curve corresponding to the public key print("Points on the elliptic curve corresponding to the public key:") print(" x coordinate (hexadecimal):", hex(public_key_point.x())) print(" y coordinate (hexadecimal):", hex(public_key_point.y())) print("Keccak-256 hash:", public_key_hash.hex()) print("Checksum:", ()) print("Full address data:", full_payload.hex()) print("TRC address data:", trc_address_hex) print("TRC Address:", trc_address) print('\n') def test2(): # Specify the private key (please replace it with your actual private key) private_key_hex = "your_private_key_hex_string" # Convert hexadecimal private key to PrivateKey object private_key = PrivateKey((private_key_hex)) # Deriving a public key from a private key public_key = private_key.public_key # Generate TRC address from public key address = public_key.to_base58check_address() print("指定的Private key (hexadecimal):", private_key_hex) print("Public Key (hexadecimal):", public_key.hex()) print("TRC Address:", address) print('\n') test1() test2()
This is the end of this article about using Python to calculate TRC20 address. For more related contents of Python to calculate TRC20 address, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!