Exporting private keys
Privy enables your users to export the private key or seed phrase for their embedded wallet. This allows them to use their embedded wallet address with another wallet client, such as MetaMask or Phantom.
To have your user export their embedded wallet’s private key or seed phrase, use Privy’s exportWallet
method:
When invoked, exportWallet
will open a modal where your user can copy the full private key or seed phrase for their embedded wallet. The modal will also link your user to a guide for how to load their embedded wallet into another wallet client, such as MetaMask or Phantom.
If your user is not authenticated
or has not yet created an embedded wallet in your app, this method will fail.
As an example, you might attach exportWallet
to an export wallet button in your app:
Please note that exporting the seed phrase for Solana wallets is not supported, as different external wallet clients use different HD derivation paths to derive Solana wallet addresses from a seed phrase. Privy supports exporting Solana wallets by private key to ensure that users maintain the same address when importing their wallet into an external wallet client like Phantom.
If your application uses smart wallets on EVM networks, exporting the wallet will export the private key for the smart wallet’s signer, and not the smart wallet itself. Users can control their smart wallet via this private key, but will be required to manually use it to sign calls to the contract for their smart wallet directly to use the smart wallet outside of your app.
Exporting HD wallets
If your user has multiple embedded wallets, you can export the private key for a specific wallet by passing the address of your desired wallet as an address
parameter to the exportWallet
method:
If no address
is passed to exportWallet
, Privy will default to exporting the wallet at walletIndex: 0
.
When your user exports their embedded wallet, their private key or seed phrase is assembled on a different origin than your app’s origin. This means neither you nor Privy can ever access your user’s private key or seed phrase. Your user is the only party that can ever access their full private key or seed phrase.
To have your user export their embedded wallet’s private key or seed phrase, use Privy’s exportWallet
method:
When invoked, exportWallet
will open a modal where your user can copy the full private key or seed phrase for their embedded wallet. The modal will also link your user to a guide for how to load their embedded wallet into another wallet client, such as MetaMask or Phantom.
If your user is not authenticated
or has not yet created an embedded wallet in your app, this method will fail.
As an example, you might attach exportWallet
to an export wallet button in your app:
Please note that exporting the seed phrase for Solana wallets is not supported, as different external wallet clients use different HD derivation paths to derive Solana wallet addresses from a seed phrase. Privy supports exporting Solana wallets by private key to ensure that users maintain the same address when importing their wallet into an external wallet client like Phantom.
If your application uses smart wallets on EVM networks, exporting the wallet will export the private key for the smart wallet’s signer, and not the smart wallet itself. Users can control their smart wallet via this private key, but will be required to manually use it to sign calls to the contract for their smart wallet directly to use the smart wallet outside of your app.
Exporting HD wallets
If your user has multiple embedded wallets, you can export the private key for a specific wallet by passing the address of your desired wallet as an address
parameter to the exportWallet
method:
If no address
is passed to exportWallet
, Privy will default to exporting the wallet at walletIndex: 0
.
When your user exports their embedded wallet, their private key or seed phrase is assembled on a different origin than your app’s origin. This means neither you nor Privy can ever access your user’s private key or seed phrase. Your user is the only party that can ever access their full private key or seed phrase.
To export a wallet’s private key via the REST API, use the /v1/wallets/{wallet_id}/export
endpoint. This endpoint uses Hybrid Public Key Encryption (HPKE) to securely transmit the private key.
A wallet must have a policy attached that explicitly permits private key exports via the
exportPrivateKey
method. See our example
policies
for reference on how to configure this.
The endpoint will return the encrypted private key along with the encapsulation information needed for decryption:
Decrypting the Private Key
The exported private key is encrypted using Hybrid Public Key Encryption (HPKE) with the following configuration:
- KEM: DHKEM_P256_HKDF_SHA256
- KDF: HKDF_SHA256
- AEAD: CHACHA20_POLY1305
- Mode: BASE
To decrypt the private key, you’ll need to use these same parameters along with your recipient private key. Here’s how to implement the decryption in several languages: