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.- Ethereum
- Solana
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 auiConfig object:Complete Example
Here’s a complete example with proper validation and error handling:UI Configuration Options
TheexportKey method accepts an optional uiConfig object to customize the export modal:
Custom title displayed at the top of the export modal.Example:
Description explaining what the private key is and its importance.Example:
Warning message emphasizing that the key should never be shared.Example:
Loading text displayed while the export modal is initializing.Example:
Description for HD (Hierarchical Deterministic) wallet exports.Example:
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
Always confirm user intent
Always confirm user intent
Use confirmation dialogs before exporting to ensure users understand the implications:
Educate users about security
Educate users about security
Provide clear warnings and best practices:
Validate wallet existence
Validate wallet existence
Always check that a wallet exists before attempting export:
Handle errors gracefully
Handle errors gracefully
Provide clear error messages and recovery options:
Never log or store exported keys
Never log or store exported keys
Your application should never log, store, or transmit exported private keys:
Customize for your brand
Customize for your brand
Use
uiConfig to match your application’s branding:Security Considerations
What happens during export
- User initiates export through your application
- MoonKey opens secure modal in an isolated environment
- Private key is assembled client-side in a separate origin
- User copies key directly from the secure modal
- 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
Export button is disabled
Export button is disabled
Export fails with error
Export fails with error
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
readystate before calling export
Modal doesn't appear
Modal doesn't appear
Verify:
- Correct import path for your chain type
useExportKeyis called within a component- Component is wrapped by
MoonKeyProvider - No popup blockers are interfering
Can't import exported key into MetaMask
Can't import exported key into MetaMask
Ensure:
- Copying the complete private key (including
0xprefix 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)
- Open MetaMask
- Click account icon → “Import Account”
- Select “Private Key” option
- Paste the exported private key (with
0xprefix) - Click “Import”
Phantom (Solana)
- Open Phantom
- Settings → Add / Connect Wallet
- Select “Import Private Key”
- Paste the exported private key
- Click “Import”
Other Wallet Clients
Most wallet clients support private key import through similar flows. Consult the specific wallet’s documentation for detailed instructions.Related Documentation
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:- Test the flow with test wallets on testnet
- Educate your users about private key security
- Provide support documentation for common issues
- Consider adding recovery mechanisms for users who lose keys
- Monitor usage to understand how users interact with export