2

I know my Ethereum address, my Metamask wallet will give it to me, and I can run :

web3.eth.coinbase

But I want to know what my public key is.
Is there any way I can find that ?

(the reason I want to know a public key because I believe I need it to verify if a particular signed message was truely signed by that key)

2
  • If the message signature includes the v value (in addition to r and s)—which is the norm for signatures in Ethereum—then you can recover the public key, hash it to get the address, and see if the address matches. (You don't need to know the public key in advance.)
    – user19510
    Feb 23, 2018 at 3:23
  • programtheblockchain.com/posts/2018/02/17/… may help.
    – user19510
    Feb 23, 2018 at 3:30

2 Answers 2

2

Using web3js it's not possible to fetch the public key of an account using its private key. Lots of people are getting confused between address and public key as both are different things. But if you want to use any other 3rd party lib, you can use it via ethereumjs-wallet

Sample - https://piyopiyo.medium.com/how-to-get-ethereum-public-key-from-private-key-javascript-835c276e39bc

1

I know it's been a while, but this should work https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#privatekeytoaccount

1
  • You can use recover to verify a signed message. But otherwise the public key is not exposed by web3.
    – Ismael
    Jun 21, 2019 at 4:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.