How can I get public & private keys from getSigner() function. I want this to send public key as an argument to function call & listen for an event in server which then encrypts a message using the public key and sent to browser which the user can decrypt with their private key.

1 Answer 1


You can only access the public and private key if you built the signer from a mnemonic or a private key. The relevant fields are on the signer type Wallet in ethers.

Specifically, wallet.publicKey and wallet.privateKey (from the "Wallet Examples" section of the docs below)

If the signer is remote you cannot get the private key.

If you just want to sign data, you can use the signMessage and _signTypedData methods on the signer which works for any signer type and can be verified against the address using ethers.utils.verifyMessage.

All of the relevant docs are here: https://docs.ethers.io/v5/api/signer/

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.