Skip to main content
MoonKey makes it easy to access a user’s embedded wallet so you can help them take onchain actions. Every authenticated user with an embedded wallet has access to their wallet through the SDK.
MoonKey currently supports embedded wallets only. Each user can have one embedded wallet per chain type (Ethereum or Solana).
Import paths:
  • useMoonKey comes from @moon-key/react-auth (the base package)
  • useWallets comes from @moon-key/react-auth/ethereum for Ethereum or @moon-key/react-auth/solana for Solana

React SDK

Usage

Wallet properties

The user.wallet object contains the following properties:
string
The wallet’s Ethereum address (e.g., 0x1234...5678)
string
The chain type, always 'ethereum' for Ethereum wallets
WalletClient
The wallet client instance from viem for performing operations

Alternative: Using useWallets

You can also access Ethereum wallets using the useWallets 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 the ready boolean returned by the useMoonKey or useWallets hooks. The ready flag will be:
  • false while MoonKey is loading wallet information
  • true once 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

Import from: @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
Returns:
  • Complete user object with all linked accounts
  • Authentication state
  • Wallet as part of the user object

useWallets

Import from: @moon-key/react-auth/ethereum (for Ethereum wallets)
Use when:
  • 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
Returns:
  • Array of wallet objects (chain-specific)
  • Ready state for wallet loading
For most use cases, useMoonKey is recommended as it provides both user and wallet information in a single hook.

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

Wait for the SDK to be ready before accessing wallet information:
Not all users will have wallets. Provide clear next steps:
Always pass the wallet object to transaction methods:
TypeScript helps catch wallet-related errors:
Show shortened addresses in UI for better UX:

Troubleshooting

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
If ready stays false:
  • Verify MoonKeyProvider is properly configured
  • Check browser console for errors
  • Ensure appId is correct
  • Try refreshing the page
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