Skip to content

Instantly share code, notes, and snippets.

@mikoim
Created October 17, 2021 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikoim/c833b4b7c33021ee12e01eb9b327d58d to your computer and use it in GitHub Desktop.
Save mikoim/c833b4b7c33021ee12e01eb9b327d58d to your computer and use it in GitHub Desktop.
Retrieve Ethereum address from private key with web3.py
from web3.auto import w3
from eth_account.messages import encode_defunct
message = encode_defunct(text='')
signed_message = w3.eth.account.sign_message(message, private_key='0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80') # Hardhat
address = w3.eth.account.recover_message(message, signature=signed_message.signature)
print(address)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment