- Manually - When you call MoonKey’s
fundWalletmethod - Automatically - When the user attempts to send a transaction but has insufficient funds
Manually invoking funding
Once you’ve enabled funding methods for your app in the Dashboard, use theuseFundWallet hook to invoke the funding flow:
fundWallet method will open a modal with funding options for the user. If only one funding method is enabled, MoonKey will navigate directly to that flow.
Automatically invoking funding
When a user attempts to send a transaction but doesn’t have sufficient funds, MoonKey will automatically show them an “Add funds” button in the transaction modal that enables them to invoke funding flows. This helps users complete their intended actions without leaving your application.Setting funding parameters in code
You can override your Dashboard configuration by passing parameters tofundWallet:
Basic parameters
string
required
The wallet address to fund.
string
The Ethereum chain to fund on. Use
'eip155:1' for Ethereum mainnet, 'eip155:8453' for Base, etc.If not specified, defaults to the chain configured in your Dashboard.string
The amount of the asset to fund as a decimal string (e.g.,
'0.1').If not specified, defaults to the amount configured in your Dashboard.'native-currency' | 'USDC' | {erc20: string}
The asset to fund with:
'native-currency'- The chain’s native currency (ETH, etc.)'USDC'- USDC stablecoin{erc20: '0x...'}- Any ERC-20 token by contract address
'native-currency'.Testnets are not supported. Only use mainnet chain IDs.
Examples
Fund with ETH
Fund with the native currency (ETH):Fund with USDC
Fund with USDC stablecoin:Fund with arbitrary ERC-20
Fund with any ERC-20 token:Fund on different networks
Fund on various EVM networks:Common chain IDs
Callbacks
To understand when users have gone through a funding flow, use theonUserExited callback with the useFundWallet hook:
Callback parameters
TheonUserExited callback receives an object with:
string
The wallet address that was funded.
string
The chain ID where funding occurred.
string
The funding method used (e.g.,
'card').bigint
The current balance of the wallet being funded.
Onboarding flow example
Prompt new users to fund their wallet as part of onboarding:Customizing the UI
Customize the “Receive funds” screen with theuiConfig option:
UI configuration options
string
Custom title for the “Receive funds” screen.
string
Custom subtitle for the “Receive funds” screen.
Complete example
Here’s a complete example with amount selection and funding:Best practices
Set appropriate default amounts
Set appropriate default amounts
- Consider typical transaction costs on the target network
- Use smaller amounts for L2s (Base, Arbitrum, Optimism) where gas is cheap
- Use larger amounts for Ethereum mainnet where gas is expensive
- Make amounts easy to adjust before purchase
Choose the right network
Choose the right network
- Use L2s for better user experience (lower fees)
- Match the network to where your contracts are deployed
- Consider which networks MoonPay supports
Communicate funding status
Communicate funding status
- Explain that purchases are not instant
- Show expected delivery times
- Provide transaction status updates
- Handle edge cases gracefully
Use callbacks effectively
Use callbacks effectively
- Track funding completion with
onUserExited - Navigate users appropriately based on balance
- Log funding events for analytics
- Handle insufficient balance scenarios