Skip to main content
MoonKey enables your users to export the private key for their embedded wallet. This allows them to use their embedded wallet address with another wallet client, such as MetaMask or Phantom, or to back up their wallet for recovery purposes.
Exporting private keys is a sensitive operation. Once exported, the private key gives complete control over the wallet and all its assets. Users should be educated about proper key storage and security practices.

Overview

When users export their wallet, they receive:
  • Full private key for their embedded wallet
  • Complete control over their wallet, even outside your application
  • Ability to import into other wallet clients (MetaMask, Phantom, etc.)
  • Self-custody of their assets
When your user exports their embedded wallet, their private key is assembled in a secure environment separate from your app. This means neither you nor MoonKey can ever access your user’s full private key. Your user is the only party that can ever access it.

React SDK

MoonKey provides a simple hook-based API for wallet export in React applications.
To enable wallet export for Ethereum wallets, use the useExportKey hook from @moon-key/react-auth/ethereum:

Basic Usage

With Custom UI Configuration

You can customize the export modal’s appearance by passing a uiConfig object:

Complete Example

Here’s a complete example with proper validation and error handling:

UI Configuration Options

The exportKey method accepts an optional uiConfig object to customize the export modal:
string
Custom title displayed at the top of the export modal.Example:
string
Description explaining what the private key is and its importance.Example:
string
Warning message emphasizing that the key should never be shared.Example:
string
Loading text displayed while the export modal is initializing.Example:
string
Description for HD (Hierarchical Deterministic) wallet exports.Example:
string
URL to your application’s logo to display in the export modal.Example:

Common Use Cases

Wallet Backup

Allow users to back up their wallet for recovery:

Best Practices

Use confirmation dialogs before exporting to ensure users understand the implications:
Provide clear warnings and best practices:
Always check that a wallet exists before attempting export:
Provide clear error messages and recovery options:
Your application should never log, store, or transmit exported private keys:
Use uiConfig to match your application’s branding:

Security Considerations

Private key export is a high-risk operation. Ensure your users understand:
  • Anyone with the private key has complete control of the wallet
  • Lost private keys cannot be recovered
  • Stolen private keys can result in permanent loss of funds
  • Private keys should never be shared with anyone

What happens during export

  1. User initiates export through your application
  2. MoonKey opens secure modal in an isolated environment
  3. Private key is assembled client-side in a separate origin
  4. User copies key directly from the secure modal
  5. No logging or storage occurs in your application or MoonKey’s servers

Security features

  • Isolated origin: Keys are displayed in a separate security context
  • No server access: Neither your app nor MoonKey can access the full key
  • User-only access: Only the user can view their exported key
  • No automatic storage: Keys are never automatically saved anywhere
  • Ephemeral display: Keys are only shown during the export flow

Troubleshooting

Check these conditions:
  • SDK is ready (ready === true)
  • User is authenticated (isAuthenticated === true)
  • User has a wallet (user?.wallet !== undefined)
Common causes and solutions:
  • User cancelled: User closed the modal - this is expected behavior
  • No wallet found: Ensure wallet creation is complete before export
  • Network error: Check internet connection and try again
  • SDK not ready: Wait for ready state before calling export
Ensure:
  • Copying the complete private key (including 0x prefix for Ethereum)
  • Using correct import method in MetaMask (Import Account → Private Key)
  • Private key format matches wallet type (hex for Ethereum, base58 for Solana)

Importing Exported Wallets

After exporting, users can import their wallet into various wallet clients:

MetaMask (Ethereum)

  1. Open MetaMask
  2. Click account icon → “Import Account”
  3. Select “Private Key” option
  4. Paste the exported private key (with 0x prefix)
  5. Click “Import”

Phantom (Solana)

  1. Open Phantom
  2. Settings → Add / Connect Wallet
  3. Select “Import Private Key”
  4. Paste the exported private key
  5. Click “Import”

Other Wallet Clients

Most wallet clients support private key import through similar flows. Consult the specific wallet’s documentation for detailed instructions.

Export Key UI Component

Detailed UI component documentation and customization

Get User Wallets

Learn how to access user wallets

Create a Wallet

Create embedded wallets for users

Wallets Overview

Complete guide to MoonKey’s wallet infrastructure

Next Steps

After implementing wallet export:
  1. Test the flow with test wallets on testnet
  2. Educate your users about private key security
  3. Provide support documentation for common issues
  4. Consider adding recovery mechanisms for users who lose keys
  5. Monitor usage to understand how users interact with export
For more details on customizing the export UI, see the Export Key UI Component documentation.