A minimal viable demo of a crypto onramp service using Crossmint's Headless Checkout API, implemented as a Next.js app.
- Simple token purchase flow on Base Sepolia
- Integration with Crossmint's Headless Checkout API
- User authentication via Crossmint (email, Google, Farcaster)
- KYC verification using Persona
- Simulated wallet connection
- Checkout.com payment form integration
- Progress tracking page
- Frontend: Next.js (React), Tailwind CSS
- Backend: Next.js API routes
- API Integration: Crossmint Authentication, Crossmint Headless Checkout, Persona, Checkout.com
- Node.js 18+ and npm
-
Clone the repository:
git clone <repository-url> cd onrampv3
-
Install dependencies:
npm install
-
Create a
.env.localfile with the following variables:# Crossmint API Keys NEXT_PUBLIC_CROSSMINT_ENVIRONMENT=staging NEXT_PUBLIC_CROSSMINT_API_KEY=YOUR_CROSSMINT_PUBLIC_API_KEY CROSSMINT_API_SECRET=YOUR_CROSSMINT_SECRET_API_KEY # Checkout.com API Keys NEXT_PUBLIC_CHECKOUTCOM_PUBLIC_KEY=YOUR_CHECKOUTCOM_PUBLIC_KEY -
Run the development server:
npm run dev
-
Open http://localhost:3000 in your browser to see the app.
- User lands on the form page and enters amount of tokens to purchase
- User clicks "Continue" and is prompted to authenticate using Crossmint
- After authentication, user confirms email and enters Ethereum wallet address
- User clicks "Buy Tokens" to create an order via Crossmint's API
- If KYC is required, the Persona verification flow is launched
- After KYC approval, Checkout.com payment form is shown
- After successful payment, completion screen is displayed
/app
/api
/create-order # API route for creating orders
/get-order-status # API route for polling KYC status
/providers
Providers.tsx # Authentication providers wrapper
/progress # Progress tracking page
page.tsx # Main purchase form page
layout.tsx # Root layout
/components
AuthButton.tsx # Authentication button component
KYCStatus.tsx # KYC verification component
WalletConnectMock.tsx # Simulated wallet connection
PaymentForm.tsx # Checkout.com payment form
/lib
crossmint.ts # Crossmint API helpers
utils.ts # Utility functions including logging utilities
The application uses Crossmint's authentication system to provide a seamless user experience:
-
Authentication Methods: Users can authenticate using:
- Email (magic link)
- Google OAuth
- Farcaster
-
Provider Setup:
- The app uses
CrossmintProviderandCrossmintAuthProviderfrom the@crossmint/client-sdk-react-uipackage - Configuration is done in
app/providers/Providers.tsx
- The app uses
-
Authentication Flow:
- User enters the amount they want to purchase
- User is prompted to authenticate using one of the available methods
- After successful authentication, user's email is pre-filled in the form
- Authenticated state is maintained throughout the app
-
Implementation Example:
import { useAuth } from '@crossmint/client-sdk-react-ui'; function MyComponent() { const { user, login, logout } = useAuth(); // Check if user is authenticated if (user) { return <div>Welcome, {user.email}!</div>; } // Show login button if not authenticated return <button onClick={() => login()}>Login</button>; }
-
Environment Setup:
- To enable authentication, you need to set up a project in the Crossmint developer portal
- Add your API keys to
.env.localas shown in the Installation section
The application includes a modular logging system for development and debugging purposes:
-
Global Control: All debug logging can be enabled/disabled by setting the
DEBUG_ENABLEDflag inlib/utils.ts -
Namespaced Loggers: Each module uses its own namespaced logger, making it easy to identify the source of log messages
-
Usage Example:
import { createLogger } from '@/lib/utils'; // Create a logger with a namespace const logger = createLogger('API:EXAMPLE'); // Log info messages with optional data logger.log('Operation completed', { id: '123', status: 'success' }); // Log error messages logger.error('Operation failed', error);
-
Disabling Logs for Production: Set
DEBUG_ENABLED = falseinlib/utils.tsto disable all debug logging
- This is a demo application and not intended for production use
- For a production implementation, proper security measures should be implemented
- API keys in this demo are using Crossmint's staging environment
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.
A streamlined cryptocurrency onramp application built with Next.js and Crossmint API for purchasing USDC.
- Buy USDC using fiat currency (USD)
- Authentication with Crossmint
- Streamlined checkout flow
- Mobile-responsive design
- Country-specific restrictions
- Wallet integration
# Install dependencies
npm install
# Start the development server
npm run devOpen http://localhost:3000 with your browser to see the result.
Create a .env.local file with the following variables:
NEXT_PUBLIC_CROSSMINT_API_KEY=your_crossmint_api_key
CROSSMINT_SECRET_KEY=your_crossmint_secret_key
This project is configured for easy deployment on Vercel.
- Push your code to a Git repository (GitHub, GitLab, or Bitbucket)
- Import your project on Vercel
- Vercel will automatically detect Next.js and use the optimal build settings
- Set your environment variables in the Vercel dashboard
- Deploy!