Skip to content

Instantly share code, notes, and snippets.

@ColonelJ
Created October 26, 2019 00:54
Show Gist options
  • Save ColonelJ/b1d149cd49611e55ffde2fe132ad2f74 to your computer and use it in GitHub Desktop.
Save ColonelJ/b1d149cd49611e55ffde2fe132ad2f74 to your computer and use it in GitHub Desktop.
TRON private key to address
import sys
import ecdsa
import hashlib
import base58
from sha3 import keccak_256
def privkey_to_address(privkey):
privkey = bytes.fromhex(privkey)
s = ecdsa.SigningKey.from_string(privkey, curve = ecdsa.SECP256k1)
pubkey = s.verifying_key.to_string().hex()
address = '41' + keccak_256(bytes.fromhex(pubkey)).digest()[12:32].hex()
checksum = hashlib.sha256(hashlib.sha256(bytes.fromhex(address)).digest()).digest()[0:4].hex()
addrchecksum = address + checksum
base58addr = base58.b58encode(bytes.fromhex(addrchecksum)).decode('utf-8')
return base58addr
def main():
print(privkey_to_address(sys.argv[1]))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment