4

I know there are ways to get public key from private key using other then web3js tools (EthereumJS: How to get public key from private key and https://kobl.one/blog/create-full-ethereum-keypair-and-address/) Also, there is a way to get public key from address having a transaction sent from that address – Get public key of any ethereum account

I am looking for a way to get public key using web3js. Is there a way to do it?

user652061
  • 473
  • 2
  • 5
  • 9
  • What data you have? If you have the private key the first question should be good, if you have a signed transaction the second is correct. If you have the UTC or JSON file you canuse the first after loading the file with a wallet. – Ismael Mar 07 '18 at 19:53
  • I have all of them, but I cannot find a way to get public key using web3.js only. – user652061 Mar 08 '18 at 07:53
  • I'm afraid that both versions of web3 (v0.20 and v1.0) do not expose the public key, only the private key and the address. You will need a third party library like ethereumjs-wallet that implements a getPublicKey() function. – Ismael Mar 08 '18 at 13:45

1 Answers1

2

Yes, you can retrieve public key given you have a private key using web3js web3.eth.accounts.privateKeyToAccount(privateKey);

kajamaki
  • 29
  • 3
  • 11
    The documentation doesn't show a way to get the public key only the address and private key. – Ismael May 07 '19 at 17:40