In this guide, we’ll explore how to use the Profiles feature in Smart Wallet to request and validate user information
like email addresses and physical addresses for a simple checkout flow.
The Profiles feature allows developers to request personal information from Smart Wallet users during a transaction. This is useful for applications that need:
Email addresses
Physical addresses
Phone numbers
Names
Smart Wallet handles the collection of this information and it is left to you to validate it and store it as you see fit
while following the standards and regulations in place.
Privacy First
Users always have full control over their data. They can choose to share or withhold any information, and they’re clearly shown what data you’re requesting.
Now, let’s create a simple UI to request profile data from users along with a transaction.
We’ll create a page with checkboxes to select which data to request and a button to submit the request
along with a transfer of 0.01 USDC to an address on Base Sepolia.
Smart Wallet requires callback URLs to use HTTPS, even for local development.
For local testing, use a secure tunnel service like ngrok and update
the ngrokUrl variable with your tunnel URL.
To start ngrok, run the following command:
[Terminal]
Copy
Ask AI
ngrok http 3000
If you don’t have ngrok installed, you can install it with the following command:
If the API validation check is successful, you MUST return the original calls in the response of the API endpoint as it’s shown in the validation API section.
If you don’t, the wallet will return an error.
You can also return a new set of calls to be made after the data is validated.
Now, let’s create an API endpoint to validate the data received from Smart Wallet.
This endpoint will check for valid formats and return errors if needed.
Wallet Validation
Smart Wallet will make some basic validation of the data before sending it to your callback URL.
This includes checking that the email is a valid email address and the physical address is a valid address.
If the data is invalid, Smart Wallet will return an error to the user and not make the callback.
[app/api/data-validation/route.ts]
Copy
Ask AI
// app/api/data-validation/route.tsexport async function POST(request: Request) { const requestData = await request.json(); try { // Extract data from request const email = requestData.requestedInfo.email; const physicalAddress = requestData.requestedInfo.physicalAddress; const errors = {}; // Example: Reject example.com emails if (email && email.endsWith("@example.com")) { errors.email = "Example.com emails are not allowed"; } // Example: Validate physical address if (physicalAddress) { if (physicalAddress.postalCode && physicalAddress.postalCode.length < 5) { if (!errors.physicalAddress) errors.physicalAddress = {}; errors.physicalAddress.postalCode = "Invalid postal code"; } if (physicalAddress.countryCode === "XY") { if (!errors.physicalAddress) errors.physicalAddress = {}; errors.physicalAddress.countryCode = "We don't ship to this country"; } } // Return errors if any found if (Object.keys(errors).length > 0) { return Response.json({ errors, /*request: { calls: [], // Replace the old calls with new ones chainId: numberToHex(84532), // Base Sepolia version: "1.0", },*/ }); } // Success - no validation errors - you HAVE to return the original calls return Response.json({ request: { calls: requestData.calls, chainId: requestData.chainId, version: requestData.version, }, }); } catch (error) { console.error("Error processing data:", error); return Response.json({ errors: { server: "Server error validating data" } }); }}
When a user visits your application and connects their Smart Wallet, the following process occurs:
User connects their Smart Wallet: The user clicks “Sign in with Smart Wallet” and authorizes the connection.
App requests profile data: Your app calls wallet_sendCalls with the dataCallback capability, a list of calls to be made, a list of requested data types, and a callback URL to call with the data.
Smart Wallet prompts the user: The wallet shows a UI asking the user to share the requested information.
User provides data: The user enters/confirms their information in the Smart Wallet interface.
Data is validated: Smart Wallet sends the data to your callback URL for validation.
Validation response: Your API validates the data and returns success or errors as well as any new calls to be made.
Transaction completion: If validation passes, the wallet returns the data to your application.
The Profiles feature in Smart Wallet provides a secure and user-friendly way to collect necessary user information for your onchain app. By following this guide, you’ve learned how to:
Request profile data from Smart Wallet users
Validate that data through a callback API
Process and display the information in your application
This integration simplifies user onboarding and data collection while maintaining user privacy and control.