Configuration
Configure automatic wallet creation by setting theembeddedWallets.createOnLogin property in your MoonKeyProvider:
- Ethereum
- Solana
When to Use Each Option
’always’
Create a wallet for every user, regardless of whether they already have one. Use cases:- Web3-first applications where every user needs a wallet
- Applications that require blockchain transactions for core functionality
- NFT platforms, DeFi apps, or blockchain games
- New users get a wallet immediately upon first login
- Returning users get a wallet on their next login if they don’t have one
- Simple and straightforward approach for Web3 applications
’none’
Disable automatic wallet creation entirely. Use cases:- Applications where wallet creation should be user-initiated
- When you want full control over when wallets are created
- Authentication-only implementations
- No wallets are created automatically
- You must manually create wallets using the
useCreateWallethook - Gives you complete control over the wallet creation flow
'none', create wallets manually:
How It Works
When automatic wallet creation is enabled, MoonKey checks the following during the login flow:- User authenticates — User completes authentication (email OTP, OAuth, wallet signature, etc.)
- Check configuration — MoonKey checks the
createOnLoginsetting - Evaluate conditions — Based on the setting and user’s current wallet status
- Create wallet — If conditions are met, MoonKey generates a self-custodial embedded wallet
- User session — User’s session now includes wallet information
Accessing Created Wallets
Once a wallet is created (automatically or manually), you can access it through theuseMoonKey hook:
Best Practices
Choose the Right Strategy
| Application Type | Recommended Setting | Reason |
|---|---|---|
| DeFi Platform | 'always' | All users need wallets for trading |
| NFT Marketplace | 'always' | Core functionality requires wallets |
| Gaming | 'always' | In-game assets need wallet storage |
| Social + Crypto | 'always' | Ensure all users can access Web3 features |
| Hybrid App | 'always' or 'none' | Choose based on how central wallets are |
| Auth Only | 'none' | Manual wallet creation on demand |
Consider User Experience
For Web3-native applications:- Use
'always'for immediate wallet access - Users expect wallets to be available immediately
- Reduces friction in the onboarding flow
- Use
'none'and create wallets when users need them - Allow users to understand your app before getting a wallet
- Provide education about what a wallet is and why they need it when you create it manually
Environment-Specific Configuration
You can configure different automatic wallet creation settings for different environments:Combining with Manual Creation
You can combine automatic wallet creation with manual creation for more complex flows:Troubleshooting
Wallet not created after login
Possible causes:createOnLoginis set to'none'- Authentication didn’t complete successfully
- Configuration error in the provider
Multiple wallets created
Possible causes:- Using
'always'creates a wallet on every login - User logged in multiple times during development/testing
'always'. Each authentication creates a new wallet. If you want to prevent multiple wallets, use 'none' and create wallets manually with checks:
Need to create wallet immediately
Possible causes:- Automatic creation is disabled
- Need wallet before user completes authentication
'always':
Related Documentation
- Manual Wallet Creation — Create wallets on-demand
- Wallet Management — Managing user wallets
- Setup Guide — Initial MoonKey configuration
- Examples — Complete code examples