MoonKey currently supports embedded wallets only. Each user can have one embedded wallet per chain type (Ethereum or Solana).
React SDK
Usage
Wallet properties
Theuser.wallet object contains the following properties:
string
The wallet’s Ethereum address (e.g.,
0x1234...5678)string
The chain type, always
'ethereum' for Ethereum walletsWalletClient
The wallet client instance from
viem for performing operationsAlternative: Using useWallets
You can also access Ethereum wallets using theuseWallets hook from @moon-key/react-auth/ethereum, which returns an array of all wallets:
Waiting for wallets to be ready
When your page loads in the user’s browser, the MoonKey SDK determines what wallet the user has by loading the secure wallet infrastructure. This process happens asynchronously. To determine if MoonKey has fully loaded the user’s wallet information, use theready boolean returned by the useMoonKey or useWallets hooks.
The ready flag will be:
falsewhile MoonKey is loading wallet informationtrueonce MoonKey has determined the current wallet state
Example with ready state
useMoonKey vs useWallets
Both hooks provide access to wallet information, but they serve slightly different purposes and have different import paths:useMoonKey
@moon-key/react-auth (base package)
Use when:
- You need access to the full user object
- You want authentication state (
isAuthenticated) - You need user profile information
- You’re working with a single wallet per user
- Complete user object with all linked accounts
- Authentication state
- Wallet as part of the user object
useWallets
- Ethereum
- Solana
@moon-key/react-auth/ethereum (for Ethereum wallets)- You only need wallet information
- You want to work with an array of wallets
- You prefer a wallet-centric API
- Future-proofing for multiple wallets per user
- Array of wallet objects (chain-specific)
- Ready state for wallet loading
Common patterns
Checking for wallet existence
Getting wallet for transactions
Displaying wallet information
Finding a specific wallet (Ethereum)
Complete example
Here’s a complete example showing wallet access and usage:Best practices
Always check the ready state
Always check the ready state
Wait for the SDK to be ready before accessing wallet information:
Handle missing wallets gracefully
Handle missing wallets gracefully
Not all users will have wallets. Provide clear next steps:
Pass wallet to transaction hooks
Pass wallet to transaction hooks
Always pass the wallet object to transaction methods:
Use TypeScript for type safety
Use TypeScript for type safety
TypeScript helps catch wallet-related errors:
Format addresses for display
Format addresses for display
Show shortened addresses in UI for better UX:
Troubleshooting
Wallet is undefined
Wallet is undefined
If
user.wallet is undefined:- Check if the user is authenticated
- Verify the SDK is ready (
ready === true) - Confirm the user has created a wallet
- Check automatic wallet creation configuration
Ready state never becomes true
Ready state never becomes true
If
ready stays false:- Verify MoonKeyProvider is properly configured
- Check browser console for errors
- Ensure appId is correct
- Try refreshing the page
Cannot access wallet properties
Cannot access wallet properties
If wallet properties are inaccessible:
- Verify you’re using the correct import path
- Check that you’re using the right SDK for your chain (ethereum vs solana)
- Ensure the user object has loaded