Documentation Index
Fetch the complete documentation index at: https://dev.moonpay.com/llms.txt
Use this file to discover all available pages before exploring further.
An example React On-Ramp integration can be found on our Github
here.
Install
To integrate MoonPay in your React app, you can use MoonPay’smoonpay-react package.
Add the provider
The first thing to do is add the MoonPay provider to the root of your React application. This will provide context throughout your app to allow you to use the MoonPay widget components.setup.ts
- Sandbox environment:
pk_test... - Production environment:
pk_live...
For Next.js
For Next.js, it’s recommended to dynamically import the MoonPay components as shown below. This ensures efficient loading of the components and prevents server-side rendering (SSR). Otherwise you will see an error message:ReferenceError: window is not defined
Variants
Embedded
Theembedded variant shows the MoonPay widget will show as part of your page, wherever you place the component. This option lets you fine-tune the placement of the widget and allows you to integrate it into a specific part of your layout. This can minimize context switching for the user.
Overlay
Theoverlay variant shows the widget as an iframe on top of your website. This option directs the user’s attention towards completing their purchase while keeping them on your website.
New tab
ThenewTab variant opens the widget in a new browser tab. This option lets the user complete their purchase in a full-screen experience. When using this option, we recommend you tell the user they’ll be taken to MoonPay in a new tab. This provides guidance to the user that this is intended and part of the purchase flow.
New window
ThenewWindow variant opens the widget in a new browser window with a fixed size. This variant is ideal if you want to provide a more controlled experience for the user while they complete their purchase.
Display
You might want to control whether the SDK is showing based on some application state. This is there thevisible prop comes into play. Using the visible prop ensures that the widget is properly shown and cleaned up as necessary. As a light example, here is how one could add a button to toggle the SDK embedded variant.
URL signing
If you’re using thewalletAddress or walletAddresses query param, you need to sign your widget URL before you can display the widget. Learn more about URL signing.
Each of our React components provides an onUrlSignatureRequested prop that takes an asynchronous function which is called whenever the URL is updated. It takes an argument of the current URL and the return value should be your generated signature, acquired by some means from your backend by signing the given URL. The widget then takes this returned signature and updates its URL to include it.