Rainbow logo
RainbowKit
2.0.0

Installation

Installation

Get up and running with RainbowKit

You can scaffold a new RainbowKit + wagmi + Next.js app with one of the following commands, using your package manager of choice:

npm init @rainbow-me/rainbowkit@latest
# or
pnpm create @rainbow-me/rainbowkit@latest
# or
yarn create @rainbow-me/rainbowkit

This will prompt you for a project name, generate a new directory containing a boilerplate project, and install all required dependencies.

Alternatively, you can manually integrate RainbowKit into your existing project.

Install RainbowKit and its peer dependencies, wagmi, viem, and @tanstack/react-query.

npm install @rainbow-me/rainbowkit wagmi viem@2.x @tanstack/react-query

Note: RainbowKit is a React library.

Import RainbowKit, Wagmi and TanStack Query.

import '@rainbow-me/rainbowkit/styles.css';
import { getDefaultConfig, RainbowKitProvider, } from '@rainbow-me/rainbowkit';
import { WagmiProvider } from 'wagmi';
import { mainnet, polygon, optimism, arbitrum, base, zora, } from 'wagmi/chains';
import { QueryClientProvider, QueryClient, } from "@tanstack/react-query";

Configure your desired chains and generate the required connectors. You will also need to setup a wagmi config. If your dApp uses server side rendering (SSR) make sure to set ssr to true.

Note: Every dApp that relies on WalletConnect now needs to obtain a projectId from WalletConnect Cloud. This is absolutely free and only takes a few minutes.

...
import { getDefaultConfig } from '@rainbow-me/rainbowkit';
const config = getDefaultConfig({
appName: 'My RainbowKit App',
projectId: 'YOUR_PROJECT_ID',
chains: [mainnet, polygon, optimism, arbitrum, base, zora],
ssr: true, // If your dApp uses server side rendering (SSR)
});

Wrap your application with RainbowKitProvider, WagmiProvider, and QueryClientProvider.

const queryClient = new QueryClient();
const App = () => {
return (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<RainbowKitProvider>
{/* Your App */}
</RainbowKitProvider>
</QueryClientProvider>
</WagmiProvider>
);
};

Then, in your app, import and render the ConnectButton component.

import { ConnectButton } from '@rainbow-me/rainbowkit';
export const YourApp = () => {
return <ConnectButton />;
};

RainbowKit will now handle your user's wallet selection, display wallet/transaction information and handle network/wallet switching.

Some build tools will require additional setup.

The Webpack v5 bundler used by Next.js and Create React App no longer provides Node polyfills, so you'll need to include these modules yourself to satisfy RainbowKit's peer dependencies. Create React App specifically requires that you polyfill Buffer.

In previous versions of RainbowKit that relied on ethers, the fs, net, and tls modules were automatically polyfilled. This is no longer the case with RainbowKit v1 + wagmi v1, which are built on viem.

Reference our Next.js Webpack Config, Next.js App Router Webpack Config, and Create React App polyfills samples for configuration guidance for your project.

The Vite bundler doesn't provide Node polyfills, so you'll need to include polyfills for global, Buffer and process.env. As an example, you can reference the polyfills in our sample Vite project.

When using Remix, all RainbowKit package entry points must be added to your list of server dependencies in your Remix config since they're published as ESM packages.

Remix also requires that you polyfill global, Buffer and process.env. Reference the polyfills in our sample Remix project.

/** * @type {import('@remix-run/dev').AppConfig} */
module.exports = {
serverDependencies: [
'@rainbow-me/rainbowkit',
'@rainbow-me/rainbowkit/wallets',
],
};

Now that your users can connect their wallets, you can start building out the rest of your app using wagmi.

Send transactions, interact with contracts, resolve ENS details and much more with wagmi’s comprehensive suite of React Hooks.

For more detail, view the wagmi documentation.

To see some running examples of RainbowKit, or even use them to automatically scaffold a new project, check out the official examples.

To try RainbowKit directly in your browser, check out the CodeSandbox links below: