[Ethereum] How to obtain the public key (using web3)

private-keypublic-keysignatureweb3js

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)

Best Answer

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

Related Topic