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.
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 exported MoonPayOnramp component with an onPaymentCreated callback.
Use useOnramp to trigger the MoonPay flow from your own UI. Calling open with OnrampProviders.MoonPay navigates the Dynamic widget to the MoonPay token selector screen.
For a fully custom integration that bypasses the Dynamic widget, import MoonPayOnramp 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:
import { MoonPayOnramp } from '@dynamic-labs/sdk-react-core'const CustomMoonPay = () => { const handlePaymentCreated = (paymentUrl: string) => { // Open in a popup, embed in an iframe, or redirect window.open(paymentUrl, '_blank', 'width=500,height=700') } return ( <MoonPayOnramp onPaymentCreated={handlePaymentCreated} token="usdc" merchantName="My App" /> )}
Without onPaymentCreated, the component opens MoonPay in a new tab automatically when the user confirms.