Skip to main content

Integrate Coinbase Wallet with CDP Embedded Wallets

Learn how to build an onchain app that seamlessly supports both existing Coinbase Wallet users and new users through CDP Embedded Wallets, providing unified authentication and wallet management.

Overview

This integration enables your app to serve two distinct user types:
  • Existing Base users: Connect with their Coinbase Wallet for a familiar experience
  • New onchain users: Create CDP Embedded Wallets via email, mobile, or social authentication
Both user types get the same app functionality while using their preferred wallet type.

What You’ll Build

  • Unified authentication flow: Single sign-in supporting both wallet types
  • Automatic wallet detection: Smart routing based on user’s existing wallet status
  • Consistent user experience: Both wallet types access the same app features

Prerequisites

  • Node.js 18+ installed
  • React application (Next.js recommended)
  • CDP Portal account with Project ID
  • Basic familiarity with Wagmi and React hooks

Installation

Install the required packages for both CDP Embedded Wallets and Coinbase Wallet support:
Terminal

Step-by-Step Implementation

Since native CDP + Coinbase Wallet integration is under development, this guide uses a dual connector approach where both wallet types are supported through separate, coordinated connectors. You can use the Coinbase Wallet Wagmi connector alongside CDP’s React provider system to create a unified experience that properly handles wallet persistence for both wallet types.

Step 1: Environment Configuration

Create environment variables for your CDP project:
.env.local
Get your CDP Project ID from the CDP Portal. ⚠️ Critical: Without a valid NEXT_PUBLIC_CDP_PROJECT_ID, the app will fail to load with “Project ID is required” errors. Also configure your domain in CDP Portal → Wallets → Embedded Wallet settings for CORS.

Step 2: Configure wagmi for Coinbase Wallet Support

Set up Wagmi with the Coinbase Wallet connector (embedded wallets will be handled separately via CDP React providers):
config/wagmi.ts

Step 3: Set Up Application Providers

Wrap your application with the necessary providers. Important: Use CDPHooksProvider to properly manage embedded wallet authentication state:
app/layout.tsx

Step 4: Create Unified Authentication Hook

Build a custom hook to manage both wallet types. Using CDPHooksProvider ensures users get their existing embedded wallets when they sign in again, rather than creating new ones each time.
hooks/useUnifiedAuth.ts

Step 5: Build Authentication Component

Create a component that presents both authentication options:
components/WalletAuthButton.tsx

Step 6: Handle Transactions for Each Wallet Type

Create a transaction component that adapts to each wallet type:
components/SendTransaction.tsx

Step 7: Complete Your App

Put everything together in your main application:
app/page.tsx

Troubleshooting

Common Issues

Coinbase Wallet connector not appearing
  • Verify the Coinbase Wallet SDK, @base-org/account, is installed and up-to-date
  • Check wagmi configuration includes Coinbase Wallet connector
  • Ensure app is running on Base or Base Sepolia network
CDP Embedded Wallet authentication failing
  • Verify CDP Project ID is correct in environment variables
  • Critical: Add your domains (e.g., http://localhost:3000, http://localhost:3001) to CDP Portal → Wallets → Embedded Wallet settings → Allowed domains
  • Ensure all required CDP packages (see above) are installed
New wallet created each time instead of signing into existing wallet
  • Ensure you’re using CDPHooksProvider with proper config in your layout
  • Verify CDP Project ID is correctly configured
  • Check that hooks are imported from @coinbase/cdp-hooks consistently
Users can’t switch between wallet types
  • Implement proper disconnect flow before connecting different type
  • Clear any cached authentication state when switching
  • Provide clear UI guidance for wallet type selection

Enhanced Integration Coming Soon

We are actively working on native Coinbase Wallet integration with CDP Embedded Wallets that will enable:
  • Unified connector: Single CDP connector to handle both wallet types seamlessly
  • Spend permissions: Sub Accounts will be able to access parent Coinbase Wallet balance with limits
  • Sub Account creation: Coinbase Wallet users will be able to create app-specific Sub Accounts

Resources

Monitor the CDP documentation for updates on enhanced Embedded Wallet Coinbase Wallet integration features.