0

I know that if I run Hardhat node, I will be provided with the addresses and private keys of the Hardhat provided accounts, like this:

Hardhat Accounts
========
Account #0: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 (10000 ETH)
Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Account #1: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8 (10000 ETH)
Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d

Account #2: 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc (10000 ETH)
Private Key: 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a

Are the public keys for these accounts as easily accessible as these? I am currently attempting to generate them via some libraries, but wanted to make sure I am not wasting my time if there is somewhere I can just pull them from. I have looked around and haven't them, but perhaps they are out there somewhere.

4
  • "Are the public keys for these accounts as easily accessible as these?" Can you tell why do you need a public key and not just an address? Sep 17 at 23:39
  • 1
    I am following a tutorial for a library that is supposed to send an encrypted message between addresses. The sender sends an object with the encrypted message and the recipient's public key. Then it can only be decrypted with the public key's corresponding private key. And since I am testing the library in Hardhat test, I would like to try to use it with the Hardhat accounts. This is my first time experimenting with private-public key pairs like this, so I hope I am thinking about this correctly.
    – Roberto
    Sep 17 at 23:46
  • You can always generate the public key from the private key yourself. However Ethereum wallets and blockchain does not expose public keys unless the address has done at least one transaction, so the model you are describing might have challengers in practice. Sep 18 at 8:25
  • Yeah, it seems I may have to. Maybe just do a quick ETH transfer function, then derive the public key after the transaction. I attempted importing another library that derives public keys from private keys, but when I tried deriving an address from the private keys, it didn't match the addresses provided from Hardhat. So I thought something was up. Thank you for the insight.
    – Roberto
    Sep 19 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.