Skip to main content
User-controlled wallets support three authentication methods, each with its own integration flow. Pick the tab for the method you want to use.
Looking for a complete working app? See user-controlled wallet sample projects for Web, iOS, Android, and React Native examples.
Build a Next.js web app that authenticates users with their Google account and creates a user-owned wallet for each authenticated user. The app displays the wallet address and the USDC balance it holds.

Prerequisites

Before you begin this tutorial, ensure you’ve:

Step 1. Configure the Google Console

Set up Google OAuth so users can sign in to your app with their Google account.
  1. Log in to the Google Cloud Console
  2. Click Select a project → New Project, enter a name (for example, “Social Login Test”), and click Create.
  3. Search for Auth in the Google Cloud Search Bar.
  4. Select Google Auth Platform, click Get started, and enter:
    • App name: for example, “Social Login App”
    • User support email: select your email
    • Audience: select External
    • Contact email addresses: type your email again
    Click Create after agreeing to the policies.
  5. Select Create OAuth client, and enter:
    • Application type: select Web application
    • Client name: for example, “Web client 1”
    • Authorized redirect URIs: type http://localhost:3000
    Users will be redirected to this URL after they log in with their Google account.
    Click Create to complete the Google OAuth setup.
  6. Copy the Google OAuth Client ID, which identifies your app with Google’s OAuth service. You need it for the next two steps.
Important: The above Google OAuth setup only allows your account to login with Google. If you want other users to authenticate: Select Audience from your Google Auth Platform menu, and click Publish app, or add more test users individually.

Step 2. Configure the Circle Console

Connect your Google OAuth client to your Circle Wallets configuration so users can sign in through your app, and copy the App ID that identifies your user-controlled wallets configuration.
  1. Log in to the Circle Developer Console.
  2. Navigate to Wallets → User Controlled → Configurator.
  3. Click on Authentication Methods → Social Logins, select Google.
    Paste your Google OAuth Client ID (from Step 1) into the Client ID (Web) field.
  4. Go to the Configurator page and copy your App ID. You need it for the next step.

Step 3. Create the web application

Build a Next.js app that authenticates users through Google OAuth and creates a wallet for each authenticated user.

3.1. Create the Next.js project

In your terminal:

3.2. Install dependencies

Install the user-controlled wallets Web SDK and supporting packages:

3.3. Add environment variables

Create a .env.local file in the project directory:
Open the .env.local file and add the following:
.env.local
  • YOUR_CIRCLE_API_KEY is your Circle Developer API key.
  • YOUR_GOOGLE_WEB_CLIENT_ID is the Google OAuth Client ID created in Step 1.
  • YOUR_CIRCLE_APP_ID is the Circle Wallet App ID obtained in Step 2.

3.4. Simplify the default layout

Replace the contents of app/layout.tsx with the minimal layout below:
app/layout.tsx
Next.js requires an app/layout.tsx file, but the default one created by create-next-app includes fonts and styling that can cause build errors in some environments.

3.5. Add unified backend route

Create a file named app/api/endpoints/route.ts and add the code below:
app/api/endpoints/route.ts
This route serves as a single backend entry point for all Circle API endpoints used by the app, mapping frontend actions to thin wrapper handlers that call the corresponding endpoints:
HandlerDescription
createDeviceTokencalls POST /v1/w3s/users/social/token to create a device-bound session used by the Web SDK for social login authentication.
initializeUsercalls POST /v1/w3s/user/initialize to create or initialize a user and return a challengeId required for wallet creation.
listWalletscalls GET /v1/w3s/wallets to retrieve the wallets associated with the authenticated user.
getTokenBalancecalls GET /v1/w3s/wallets//balances to retrieve digital asset balances for the specified user-controlled wallet.
This quickstart calls listWallets and getTokenBalance directly for simplicity. In production, apps typically store wallet and balance data in a backend database and keep it in sync using Circle webhooks for scalability.
To understand how the request fields and response data for these handlers and their corresponding endpoints are used, follow the app flow in Step 4 below.

​3.6. Add UI and frontend code

Replace the contents of app/page.tsx with the code below:
app/page.tsx
This page renders the UI and implements all browser-side logic for the Google social login and wallet creation flow. It initializes the Web SDK, processes the Google OAuth redirect, manages short-lived state across redirects, and coordinates the sequence of actions required to create and display the wallet.

Step 4. Run the app flow

  1. Start the dev server:
  1. Open http://localhost:3000 in your browser to view the app.
  1. Complete the Google authentication and wallet creation flow:
    1. Click Create device token: The Web SDK generates a unique deviceId, which identifies the user’s browser. Your backend exchanges the deviceId for temporary verification tokens (deviceToken, deviceEncryptionKey) used by the Web SDK to allow Google authentication.
    2. Click Login with Google: The Web SDK starts the Google OAuth authentication process. After the user signs in with Google, the SDK sends the OAuth result to Circle. Circle validates the login and returns a userToken and encryptionKey, which together represent an authenticated Circle user session.
    3. Click Initialize user: Your backend initializes the user using the userToken. If the user hasn’t created a wallet yet, Circle returns a challengeId to create one. If the user is already initialized, the app loads the existing wallet instead.
    4. Click Create wallet: The Web SDK executes the challenge using the challengeId. The user approves the action, and Circle creates the wallet.
  2. Once the flow completes:
    • The app displays the wallet address, blockchain, and USDC balance.
    • You can verify the user was created in the Circle Dev Console:
      Wallets → User Controlled → Users.

Step 5. Fund the wallet

Fund the new wallet manually through the Circle Faucet and confirm the updated balance in the app.
  1. Copy the wallet address (0x...) from the web app UI.
  2. Visit the official Circle Faucet.
  3. Select Arc Testnet as the blockchain network.
  4. Paste the wallet address in the Send to field.
  5. Click Send USDC.
  6. Return to the app and walk through the flow again.
    Note: Use the same Google account to show the same wallet.
  7. The app will display the updated USDC balance.
In this step, you’re acting as the end user to fund your user-controlled wallet for testing. In production, app developers don’t control user wallets or private keys. Instead, users typically fund wallets themselves, but apps may also fund using faucets or airdrops without requiring wallet access.