Skip to content

Instantly share code, notes, and snippets.

@Rami-Majdoub
Forked from Breta01/get public key.ts
Created March 17, 2022 05:15
Show Gist options
  • Save Rami-Majdoub/c3d0e5da6af365517e8221de14f11f40 to your computer and use it in GitHub Desktop.
Save Rami-Majdoub/c3d0e5da6af365517e8221de14f11f40 to your computer and use it in GitHub Desktop.
Requesting the public key from MetaMask
// Account is account address provided as string
// App must have access to the specified account
const account = "0x012...bc"
// Key is returned as base64
const keyB64 = await window.ethereum.request({
method: 'eth_getEncryptionPublicKey',
params: [account],
}) as string;
const publicKey = Buffer.from(keyB64, 'base64');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment