Onramp Funds to Embedded Smart Wallets with Coinbase
This Recipe demonstrates how to integrate the Coinbase Onramp into an app that uses Alchemy Embedded Smart Wallets. It uses the Coinbase Developer Platform and assumes you’ve configured your smart wallet integration using @account-kit/react
.
Goal: Let users seamlessly buy crypto (e.g. ETH) via card and fund their smart wallet directly.
Prerequisites
-
Smart wallet integration using Alchemy Account Kit
-
Coinbase Developer Platform project ID
CDP_PROJECT_ID
- create one in the Coinbase Developer Portal
-
A backend (or serverless function) to keep that project ID secret
Step-by-Step Integration
1. Install Dependencies
2. Create Backend Route for Onramp URL Generation
Create a simple API route that generates the onramp URL using your CDP Project ID:
3. Create the Onramp Component
This opens a Coinbase-hosted onramp UI in a popup where the user can complete the transaction.
4. Add to Your App
Best Practices
-
Keep
CDP_PROJECT_ID
in environment variables and never expose it client-side.
Example: -
Let users change networks/assets in the Coinbase modal (default here is card ➜ ETH).
-
For user-level analytics you can pass
partnerUserId
when generating the onramp URL. -
Protect the
/onramp
API route with your app’s auth/session middleware so only the signed-in user can request an Onramp URL for their smart-wallet address. (Rate-limit or require a CSRF token if you don’t have full auth in place.)
Success!
Users can now click “Buy Crypto”, complete their purchase in a popup, and immediately spend the ETH that lands in their smart wallet.
Next Steps
- Sponsor their first transaction – set up Gas Manager so new users don’t pay gas.