Recommended: JavaScript SDK with React Hooks
For new React apps, we recommend the JavaScript SDK with React Hooks (
@dynamic-labs-sdk/react-hooks) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the React quickstart (JavaScript SDK) to get started.Overview
The MoonPay integration lets users buy crypto with fiat currency directly from your app. Once enabled, Dynamic shows a token selector screen inside the widget where the user picks a token, reviews the destination wallet, and is forwarded to MoonPay’s hosted checkout in a new tab. For a headless integration that bypasses the widget entirely, use the exportedMoonPayOnramp component with an onPaymentCreated callback.
Dashboard Setup
- Go to the Funding tab in your Dynamic developer dashboard.
- Under “Fiat on-ramps”, toggle on MoonPay and accept any additional terms.
- Save the settings.
Widget Implementation
Once enabled, users will see MoonPay listed in the widget’s deposit screen. Selecting it opens the built-in MoonPay screen where they:- Choose a token supported by MoonPay for their connected wallet’s chain.
- Review the destination wallet address.
- Click Continue to MoonPay — Dynamic opens the signed MoonPay widget in a new tab.
Programmatic Implementation
Using the useOnramp Hook
UseuseOnramp to trigger the MoonPay flow from your own UI. Calling open with OnrampProviders.MoonPay navigates the Dynamic widget to the MoonPay token selector screen.
address and token to pre-fill the widget:
Using the MoonPayOnramp Component
For a fully custom integration that bypasses the Dynamic widget, importMoonPayOnramp directly from @dynamic-labs/sdk-react-core. This renders a standalone token selector and wallet card that generates a signed MoonPay URL.
Supply an onPaymentCreated callback to intercept the URL and handle it yourself instead of opening a popup:
onPaymentCreated, the component opens MoonPay in a new tab automatically when the user confirms.
MoonPayOnramp Props
Headless: Resolving the URL Only
If you only need the signed URL (e.g. to embed it in your own iframe), usegetMoonPayUrl from @dynamic-labs-sdk/client:
Customizing the Onramp Provider List
To customise how MoonPay appears alongside other providers, use theonrampOptions override in DynamicContextProvider:
OnrampOption structure and more examples.
Supported Tokens
Supported tokens vary by chain and network. Fetch them at runtime withgetMoonPayCurrencies:
Error Handling
TheMoonPayOnramp component surfaces errors inline. When using the hook or the headless API, handle these errors explicitly:
Related
- getMoonPayUrl - Generate a signed MoonPay onramp URL
- getMoonPayCurrencies - List tokens supported by MoonPay for a chain
- useOnramp - Trigger any onramp provider from your UI
- Default Onramps - Enable and configure onramp providers
- Customizing the Onramp Experience - Override and extend the provider list