React SDK
- Ethereum
- Solana
To create an Ethereum wallet with the React SDK, use the
createWallet method from the useCreateWallet hook:Usage
Returns
Promise<Wallet>
A
Promise for the wallet object containing the created wallet’s details.Callbacks
You can optionally registeronSuccess or onError callbacks on the useCreateWallet hook:(wallet: Wallet) => void
Optional callback to run after a user successfully creates a wallet.
(error: Error) => void
Optional callback to run if there is an error during wallet creation.
Complete example
REST API
To create a new wallet for a user via the REST API, make aPOST request to:
You must specify the user ID as the owner of the wallet. You can obtain a user ID by first creating a user before creating the wallet.
Authentication
Include your Secret API Key in theAuthorization header:
Request body
'ethereum' | 'solana'
required
The type of wallet to create.
'ethereum'- Create an Ethereum/EVM wallet'solana'- Create a Solana/SVM wallet
string
required
The ID of the user who will own this wallet (e.g.,
user_2Cu2uVhYy0OVgRcO913OsqIVaPI).Response
string
Unique ID of the created wallet. This is the primary identifier for the wallet.
string
The ID of your MoonKey application.
string
The ID of the user who owns this wallet.
string
The wallet’s public address (Ethereum address or Solana public key).
'ethereum' | 'solana'
The type of wallet created.
boolean
Whether the wallet has been verified. Always
true for newly created wallets.boolean
Whether this is the user’s default wallet for this chain type.
number
Unix timestamp (in seconds) when the wallet was created.
number
Unix timestamp (in seconds) when the wallet was last updated.
Example request
Example response
Automatic vs manual wallet creation
MoonKey provides two approaches to wallet creation:Automatic creation
Configure MoonKey to automatically create wallets when users authenticate:- Apps where all users need wallets
- Gaming applications
- NFT marketplaces
- DeFi applications
- Simplest onboarding experience
Manual creation
Use theuseCreateWallet hook to create wallets programmatically:
- Apps with optional blockchain features
- Progressive onboarding flows
- Users who opt-in to web3 features
- When you want to delay wallet creation for UX reasons
Checking if a user has a wallet
Before creating a wallet, check if the user already has one:Common use cases
Onboarding flow with wallet creation
Optional wallet creation
Server-side wallet creation
Best practices
Check for existing wallets
Check for existing wallets
Always check if a user already has a wallet before attempting to create one:
Handle errors gracefully
Handle errors gracefully
Provide clear feedback when wallet creation fails:
Show loading states
Show loading states
Display loading indicators during wallet creation:
Educate users
Educate users
Explain what a wallet is and why they’re creating one:
Use callbacks for post-creation actions
Use callbacks for post-creation actions
Handle navigation or UI updates after successful wallet creation:
Secure your API keys
Secure your API keys
Never expose your Secret API Key in client-side code:
Error handling
Common errors and how to handle them:Next steps
Automatic Wallet Creation
Configure automatic wallet creation on login
Send Transactions
Learn how to send transactions with the wallet
Sign Messages
Sign messages for authentication
Export Private Key
Allow users to export their private key