Before you start
Make sure you have:- Installed the MoonKey React SDK
- Created a MoonKey app and obtained your App ID from the dashboard
Initialize the MoonKey Provider
TheMoonKeyProvider component wraps your application and provides authentication and wallet context to all child components. Import it from the appropriate blockchain-specific entry point and add it to your app’s root level.
Choose your import based on the blockchain you’re supporting:
- For Ethereum/EVM chains:
@moon-key/react-auth/ethereum - For Solana:
@moon-key/react-auth/solana
- Ethereum
- Solana
Provider configuration
TheMoonKeyProvider component accepts the following props:
Your MoonKey App ID from the dashboard. This identifies your application and determines which configuration settings to use.
Configuration options for authentication methods, embedded wallets, appearance, and behavior.Common configuration options:
loginMethods: Array of authentication methods to enable ('email','google','apple','wallet')embeddedWallets: Settings for automatic wallet creation and supported chainsappearance: Customize the UI theme and branding
Waiting for initialization
When theMoonKeyProvider first mounts, the SDK performs initialization tasks including:
- Checking for active user sessions
- Refreshing authentication tokens
- Loading user profile and wallet data
- Restoring previous authentication state
ready property from the useMoonKey hook to determine when initialization is complete.
The
ready state ensures you don’t show incorrect UI (like a login button for an already-authenticated user) during the brief initialization period.Next.js considerations
App Router (Next.js 13+)
When using Next.js App Router, your provider component must include the'use client' directive since MoonKey relies on React hooks and browser APIs:
providers.tsx
app/layout.tsx
Pages Router (Next.js 12 and earlier)
For Pages Router, wrap your app in_app.tsx:
pages/_app.tsx
Example configurations
Minimal setup
The simplest configuration with just an App ID (Ethereum):Email-only authentication
For applications that only need email authentication:Wallet-first experience
For Web3-native applications with Solana:Custom branding
Customize the appearance to match your brand:Troubleshooting
”MoonKey is not ready” errors
If you encounter errors about MoonKey not being initialized, ensure you’re:- Checking the
readystate before using MoonKey hooks - Wrapping your components with
MoonKeyProvider - Not trying to use MoonKey hooks in server components (Next.js App Router)
Hooks can only be used inside MoonKeyProvider
This error means you’re trying to use a MoonKey hook outside the provider’s scope. Make sure:- Your
MoonKeyProviderwraps all components that use MoonKey hooks - You haven’t accidentally placed the provider inside a component that’s trying to use MoonKey
- The provider is rendered before any child components try to use hooks