Skip to content

Exporting Solana wallets ​

Privy enables your users to export the full private key for their Solana embedded wallet.

This allows them to use their embedded wallet address with another wallet client, such as Phantom or Solflare in any application. For example, if a user purchases an asset in your app with their embedded wallet, they can still use that asset outside of your app by exporting their embedded wallet's private key to another wallet client.

To have your user export their embedded wallet's private key, use the exportWallet method from the useSolanaWallets hook.

tsx
const {exportWallet} = useSolanaWallets();

When invoked, exportWallet will open a modal where your user can copy the full private key for their embedded wallet. 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 as an event handler to an export wallet button in your app:

tsx
import {usePrivy, useSolanaWallets, type WalletWithMetadata} from '@privy-io/react-auth';

function ExportWalletButton() {
  const {ready, authenticated, user} = usePrivy();
  const {exportWallet} = useSolanaWallets();
  // 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 is WalletWithMetadata =>
      account.type === 'wallet' &&
      account.walletClient === 'privy' &&
      account.chainType === 'solana',
  );

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

Exporting HD wallets ​

If your user has multiple Solana 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
const {exportWallet} = useSolanaWallets();
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 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. Your user is the only party that can ever access their full private key.

INFO

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.