Onchain Vibes Store (Profiles)
How Onchain Vibes Store uses Coinbase Smart Wallet Profiles for secure user data collection during onchain checkout.
Overview
Onchain Vibes Store demonstrates how to use Smart Wallet Profiles to securely collect user information (like email and physical address) during an onchain transaction. This feature enables seamless, privacy-first data collection for e-commerce and other onchain apps.
What Are Smart Wallet Profiles?
Smart Wallet Profiles allow your app to request personal information from users as part of a transaction. Supported data types include:
- Email address
- Phone number
- Physical address
- Name
- Onchain wallet address
Users are always in control: they see exactly what you request and can choose to share or withhold any information.
How It Works in This App
- User clicks Buy: The checkout UI lets users select what info to share (email, address).
- App requests data: The app sends a transaction with a
dataCallback
capability, specifying the requested data and a callback URL for validation. - Smart Wallet prompts the user: The wallet UI collects the requested info.
- Validation: The wallet POSTs the data to your callback API for validation.
- Transaction proceeds: If validation passes, the transaction completes and the app displays the collected info.
Onchain Vibes Store Quick Demo
Skip ahead
If you want to skip ahead and just get the final code, you can find it here:
UI Walkthrough: CheckoutButton
The main logic lives in src/components/CheckoutButton.tsx
:
- The user selects which data to share (checkboxes for email/address).
- The app sends a transaction with a
dataCallback
capability. - The callback URL is set to your API endpoint (must be HTTPS, e.g. via ngrok in dev).
API Walkthrough: Data Validation
The callback API is implemented in src/api/data-validation/route.ts
:
- The API receives the user’s data, validates it, and returns errors if needed.
- If validation passes, it must return the original
calls
,chainId
, andcapabilities
. - If errors are returned, the wallet prompts the user to correct their info.
Wagmi & Wallet Setup
The app uses Wagmi and the Coinbase Wallet connector, configured for Smart Wallet and profiles:
Testing Locally
- Start your dev server:
npm run dev
- Start ngrok:
ngrok http 3000
- Set
VITE_NGROK_URL
in your.env
to your ngrok HTTPS URL - Try a purchase and share profile data
Best Practices
- Only request what you need: Ask for the minimum info required.
- Explain why: Tell users why you need each field.
- Validate thoroughly: Implement robust server-side validation.
- Handle errors gracefully: Show clear error messages.
- Use HTTPS: Your callback URL must be HTTPS (ngrok for local dev).