Skip to content

Instantly share code, notes, and snippets.

@VictorNS69
Last active March 10, 2020 15:17
Show Gist options
  • Save VictorNS69/3708d6c20a66dcf9eec235d46e02bc76 to your computer and use it in GitHub Desktop.
Save VictorNS69/3708d6c20a66dcf9eec235d46e02bc76 to your computer and use it in GitHub Desktop.
How to get the address from a public key in Python
#!/usr/bin/env python3
"""
You will need to install the pycryptodome package.
You can do it with:
pip3 install pycryptodome
Note: To install pip3, run the following command
sudo apt install python3-pip
"""
import codecs
from Crypto.Hash import keccak
# An example of public key is: a33e56a80b9dc83a4456265d877c0765cea76146e625572fc679804f8867222ca3c816433a9b6e6690b0b8e919ffa874982706e812314aae09d85fc62fc4fa3c
public_key_bytes = codecs.decode("your public key here", "hex")
keccak_hash = keccak.new(digest_bits=256)
keccak_hash.update(public_key_bytes)
keccak_digest = keccak_hash.hexdigest()
wallet_len = 40
wallet = "0x" + keccak_digest[-wallet_len:]
print("address", wallet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment