pythonethereumpublic-key

How to convert ethereum addres to public key


I need to convert ethereum address like this

0xB34080739D5B656D76089f9f21b374BA5dafA373

to public key like this

e2d3a3a43e71eb541e12504cee22ed74024969b46b9e68ea7f9e5384fe96fc04

I got the address this way

from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://sokol.poa.network'))

addr = w3.toHex(w3.sha3(text=public_key)[12:])

Maybe there is a library for that? help pls


Solution

  • This is not possible.

    An ethereum address (for an externally owner account, which is an account linked to a private key) is the last 20 bytes of keccak256(public_key). Since keccak256 is a hash function, and thus a one-way function, there is no way to recover the public key from the address.