Created
February 22, 2025 12:36
-
-
Save pcaversaccio/7f7cb592e57028a4bcf0f2dc4ae7b8e5 to your computer and use it in GitHub Desktop.
Generate a Tron address from an Ethereum hex address.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base58 | |
import hashlib | |
def eth_to_tron(eth_address): | |
eth_address_bytes = bytes.fromhex( | |
eth_address[2:] if eth_address.startswith("0x") else eth_address | |
) | |
tron_address_bytes = b"\x41" + eth_address_bytes | |
checksum = hashlib.sha256(hashlib.sha256(tron_address_bytes).digest()).digest()[:4] | |
return base58.b58encode(tron_address_bytes + checksum).decode() | |
# Generate the Tron address. | |
# Example: https://etherscan.io/tx/0x1c55527069753f048dd80762f0f0a76bf0db8eab5969f2c23a79fe5dabf31fee. | |
# The `_orderInfo.receiver` is `0x072DBc5661e560f1d2c71d662B9fab9Bc8f48BD1`. | |
eth_address = "0x072DBc5661e560f1d2c71d662B9fab9Bc8f48BD1" | |
tron_address = eth_to_tron(eth_address) | |
print(tron_address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment