Skip to content

Extract and Address from private.key

If you need to extract and print out the address stored in a private.key file, there are many ways to do it; here's one way to do it through some short Python code:

from eth_account import Account

key_path = '/path/to/private.key'

# Read the raw private key bytes
with open(key_path, 'rb') as f:
    private_key_bytes = f.read()

# Convert bytes to hex string
private_key_hex = private_key_bytes.hex()

# Load the account from the private key
acct = Account.from_key(private_key_hex)

# Print the Ethereum address
print('Address:', acct.address)