- Select the cryptocurrency they want to purchase in their preferred currency
- Add the preferred wallet address
- Add some personal details for KYC (such as address)
- Add payment details
- Submit the transaction
- Receive the cryptocurrency
Project prerequisites
To follow along with this guide, you’ll need three things:- A Magic Publishable API Key
- A web client
- MoonPay business account
make-scoped-magic-app
CLI tool to bootstrap a Next.js app with Magic authentication already baked into the client. You’re welcome to use your own client, but this tutorial and its accompanying code snippets assume the output of the make-scoped-magic-app
CLI as the starting point.
The make-scoped-magic-app
CLI tool is an easy way to bootstrap new projects with Magic. To get started, simply run the command below in the shell of your choice. Be sure to replace <YOUR_PUBLISHABLE_API_KEY>
with the Publishable API Key from your Magic Dashboard.
.env
as NEXT_PUBLIC_MAGIC_API_KEY
if you didn’t add it to the CLI command above.
From your MoonPay business dashboard, click on the “Developers” tab on the left hand side navigation. Copy the publishable key and add it to your .env
as NEXT_PUBLIC_MOONPAY_API_KEY
.
Install additional project dependencies
In addition to the packages included in the scaffold produced by themake-scoped-magic-app
CLI, you’ll also need to install @moonpay/moonpay-react
to have access to the MoonPay onramping components.
Run the following command to install the required dependencies:
Initialize MoonPay provider
Inside ofsrc/pages/index.tsx
, we need to wrap our application with the MoonPay provider. We do this by importing the MoonPayProvider
and nesting it underneath the existing MagicProvider
.
Since we’re using Next.js, it is recommended to import the provider dynamically. We will need to utilize dynamic
from next/dynamic
to do this. Inside the Home
function, create a variable named MoonPayProvider
:
TypeScript
JSX
Add MoonPayBuyWidget to UI
Now that we have MoonPay configured, we can now add the ability to use the onramping widget. Similarly to the provider we created in the previous step, it is recommended to import the component dynamically to avoid errors. At the top of thesrc/components/magic/cards/SendTransactionCard.tsx
, below the rest of the existing imports, add the following:
TypeScript
isVisible
. This will determine if the onramp overlay is displayed. Underneath the other variables, add the following:
TypeScript
overlay
: Overlays the widget on your existing interfaceembedded
: Embeds the widget into your existing interfacenewTab
: Opens in new tabnewWindow
: Opens in new window
SendTransaction
card, inside the getFaucetUrl() &&
conditional, replace the div with the following:
JSX
Test MoonPay widget
Now that we’ve configured MoonPay and added the widget to our UI, we are ready to test the functionality in the provided sandbox environment. Start your local development server and run through the Magic email OTP flow to log in. Once logged in you will notice a card displayed with the header “Send Transaction”. Click on this button to display the onramp widget. You will be instructed to select a cryptocurrency to buy along with the amount you want to buy and the preferred currency to pay for it. For the sake of this guide, we will be purchasing some ETH. Once you have made your selections and clicked “Continue”, you will be prompted to either connect to the site using your browser wallet, or to paste in the wallet address you wish to receive the crypto for. The following prompt will be to add the payment details. MoonPay provides us with dummy credit card information. Use the following card number, expiry date and CVC:- Credit card number: 4485 0403 7153 6584
- Expiry date: 12/2030
- CVC: 123
Next Steps
You now know how to integrate MoonPay with Magic and include the following features:- Simple authentication with Email OTP
- Buy funds using MoonPay onramp