What We’re Building
A Next.js application that lets users create an embedded wallet via social login, complete a KYC application, and receive a virtual Visa debit card funded by stablecoins (USDC). The complete flow covers:- Social login and embedded wallet creation with Dynamic
- Gasless USDC deposits via ZeroDev gas sponsorship
- Multi-step KYC form submitted to the Rain Card API
- Virtual card issuance, balance display, and USDC deposits
- JWT-authenticated API routes using Dynamic’s JWKS endpoint
The example app on GitHub still uses the legacy React SDK. Use it as a reference for the Rain API integration and the KYC form; follow the code on this page for the Dynamic wiring.
Prerequisites
Step 1: Install Dependencies
The JavaScript SDK is headless — it ships no login modal, wallet picker, or user profile UI. You build those screens yourself. See Authentication screens for the full list of screens to cover.
Step 2: Configure Environment Variables
.env.local
Step 3: Set Up Dynamic with Gas Sponsorship
Create the client once in its own module and register the EVM and ZeroDev extensions. ZeroDev is what makes the USDC deposit gasless, so the user never needs ETH in their embedded wallet.lib/dynamicClient.ts
QueryClientProvider and DynamicProvider. DynamicProvider is a thin binding around the client you just created — it holds no configuration of its own.
lib/providers.tsx
ZeroDev needs a project and gas policy per network. Create them in the ZeroDev V1 dashboard, then add the project IDs under Sponsor Gas in the Dynamic dashboard. See the ZeroDev Gas Sponsorship Quickstart.
app/layout.tsx
Step 4: Authenticate API Routes with Dynamic JWTs
Dynamic issues a JWT for every authenticated user. Protect your server-side API routes by verifying that token against Dynamic’s JWKS endpoint. This gives you access to the user’s verified credentials (wallet address, email) inside every handler.lib/dynamic/dynamic-auth.ts
The JWKS URI must include your environment ID. If you use a different variable
than
NEXT_PUBLIC_DYNAMIC_ENV_ID, substitute it in jwksUri above.Step 5: Build the KYC Application Flow
The KYC form collects personal, address, and financial information across three steps. On submit, a server action POSTs to your/api/apply route, which forwards the data to Rain and automatically creates a card.
Application API route
app/api/apply/route.ts
The Rain API auto-approves applications in test mode. In production, applications go through manual KYC review before a card can be created.
Calling the route from the client
Pass the Dynamic auth token as a Bearer token in every request to your API routes:Step 6: Display Card Details and Balance
Once a card is created, its reference is stored in the user’s Dynamic metadata. Retrieve the card and check the Rain balance from separate API routes, then render them in a card component.Balance API route
app/api/balance/route.ts
Card details (encrypted)
Card numbers, CVVs, and expiry dates come back from Rain encrypted. Retrieve them per session and render client-side with a show/hide toggle:app/api/card-details/route.ts
Step 7: Fund the Card with USDC
Users deposit USDC from their embedded wallet to the card’s on-chain account. Encode the ERC-20transfer with viem, then send it through sendUserOperation so ZeroDev sponsors the gas and the user never needs ETH.
Getting the wallet account and sending the sponsored transaction are plain JavaScript SDK calls — only how you read the wallet account differs by framework:
- JavaScript
- React
useDepositTokens hook used by this recipe’s Next.js app. Offer preset amounts ($5, $10, $25) and a custom input so users can quickly top up their card:
components/FundCard.tsx