Skip to main content
With funding methods enabled for your app, MoonKey will prompt users to fund their wallets at two points in their experience:
  1. Manually - When you call MoonKey’s fundWallet method
  2. Automatically - When the user attempts to send a transaction but has insufficient funds
You can configure the chain, asset, and amount that users should fund their wallets with directly in code.

Manually invoking funding

Once you’ve enabled funding methods for your app in the Dashboard, use the useFundWallet hook to invoke the funding flow:
Once invoked, the 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.
Purchases with third-party providers (like MoonPay) are not always instantaneous. There may be some time before the user completes their purchase and the funds are available in their wallet.

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 to fundWallet:

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
Defaults to '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 the onUserExited callback with the useFundWallet hook:

Callback parameters

The onUserExited 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 the uiConfig 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

  • 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
  • Use L2s for better user experience (lower fees)
  • Match the network to where your contracts are deployed
  • Consider which networks MoonPay supports
  • Explain that purchases are not instant
  • Show expected delivery times
  • Provide transaction status updates
  • Handle edge cases gracefully
  • Track funding completion with onUserExited
  • Navigate users appropriately based on balance
  • Log funding events for analytics
  • Handle insufficient balance scenarios