Skip to content

Exporting the embedded wallet

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:

tsx
import {usePrivy} from '@privy-io/react-auth';
...
const {exportWallet} = usePrivy();

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:

tsx
import {usePrivy} from '@privy-io/react-auth';

function ExportWalletButton() {
  const {ready, authenticated, user, exportWallet} = usePrivy();
  // Check that your user is authenticated
  const isAuthenticated = ready && authenticated;
  // Check that your user has an embedded wallet
  const hasEmbeddedWallet = !!user.linkedAccounts.find(
    (account) =>
      account.type === 'wallet' &&
      account.walletClient === 'privy' &&
      account.chainType === 'ethereum',
  );

  return (
    <button onClick={exportWallet} disabled={!isAuthenticated || !hasEmbeddedWallet}>
      Export my wallet
    </button>
  );
}

INFO

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:

tsx
import {exportWallet} from '@privy-io/react-auth';
...
const {exportWallet} = usePrivy();
await exportWallet({address: 'insert-your-desired-address'});

If no address is passed to exportWallet, Privy will default to exporting the wallet at walletIndex: 0.

Privy tip
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.