Skip to main content

Overview

RainbowKit is a React library that makes it easy to add wallet sign-in to your onchain application. It’s designed to work out-of-the-box and includes native support for Coinbase Wallet. By integrating RainbowKit with Coinbase Wallet, you can provide your users with a seamless onboarding experience while maintaining access to the full Coinbase Wallet feature set.

What You’ll Achieve

By the end of this guide, you will:
  • Set up RainbowKit with Coinbase Wallet support
  • Learn how to use both ConnectButton and WalletButton components
  • Configure your app to prioritize Coinbase Wallet as the primary wallet option
  • Obtain and configure a Reown project ID (required for RainbowKit projects)
You can jump ahead and use the Coinbase Wallet RainbowKit Template to get started:

Installation

After creating a new Next.js project, install the required dependencies:
Access the latest version of the Coinbase Wallet SDK (Recommended)It is to access the latest version of the Coinbase Wallet SDK in order to get the latest features and bug fixes.To do this, you can use the following command to override it:
Or you can use a specific version by adding the version to the overrides:
Make sure to delete your node_modules and package-lock.json and run a new install to ensure the overrides are applied.

Get Your Reown Project ID

Before you can use RainbowKit with Coinbase Wallet, you need to obtain a project ID from Reown Cloud.
  1. Visit Reown Cloud Dashboard
  2. Sign up for a free account or log in if you already have one
  3. Create a new project and copy the project ID.

Configuration

1. Configure wagmi with RainbowKit

Create a wagmi.ts file in your src directory to configure your blockchain connections and wallet options:
src/wagmi.ts
Replace YOUR_PROJECT_IDMake sure to replace 'YOUR_PROJECT_ID' with the actual project ID you obtained from Reown Cloud.For production applications, use environment variables:
And add to your .env.local:

2. Set Up RainbowKit Provider

Wrap your application with the necessary providers in your _app.tsx:
src/pages/_app.tsx

Usage

RainbowKit provides two main components for wallet connections: ConnectButton and WalletButton. Both components support Coinbase Wallet out of the box.

Option 1: Using ConnectButton

The ConnectButton is RainbowKit’s all-in-one wallet connection component. It displays the wallet connection modal with all available wallets, including Coinbase Wallet.
src/pages/index.tsx
When implemented, this is what it will look like:
RainbowKit Wallet Window

Option 2: Using WalletButton for Coinbase Wallet

The WalletButton component provides a direct connection to a specific wallet. This is ideal when you want to highlight Coinbase Wallet as the primary wallet option.
src/pages/index.tsx
When implemented, this is what it will look like:
Coinbase Wallet Button

Advanced Configuration

Prioritize Coinbase Wallet in Wallet List

To make Coinbase Wallet appear first in the wallet connection modal, you can customize the wallet order:
src/wagmi.ts

Customize RainbowKit Theme

RainbowKit supports extensive theming options:
src/pages/_app.tsx

Access Wallet Connection State

Use wagmi hooks to access wallet connection state throughout your app:
Profile.tsx

Switch Networks Programmatically

Allow users to switch between different chains:
NetworkSwitcher.tsx

Best Practices

Use Environment Variables

Store sensitive configuration like your Reown project ID in environment variables, not in your code:
.env.local

Enable SSR Support

Always set ssr: true in your wagmi config for Next.js applications to avoid hydration issues:

Prioritize Base Chain

Put Base as the first chain in your configuration to make it the default:

Keep Dependencies Updated

Regularly update RainbowKit, wagmi, and viem to get the latest Coinbase Wallet features and security patches:

Next Steps

Now that you have RainbowKit configured with Coinbase Wallet, you can:

Explore Coinbase Wallet Features

Learn more about Coinbase Wallet and its features

Explore RainbowKit Docs

Learn more about RainbowKit and its features

Explore wagmi Docs

Learn more about wagmi and its features

Join the Base Community

Join the Base community and get help from other developers