Skip to content

Commit 861c690

Browse files
Add RainbowKit quickstart (#2336)
* Add RainbowKit quickstart * edits --------- Co-authored-by: Alexandra Tran <[email protected]>
1 parent c9f01d4 commit 861c690

File tree

4 files changed

+182
-8
lines changed

4 files changed

+182
-8
lines changed

sdk-sidebar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const sidebar = {
1616
items: [
1717
'connect/javascript-wagmi',
1818
'connect/javascript',
19+
'connect/javascript-rainbowkit',
1920
'connect/javascript-dynamic',
2021
'connect/javascript-web3auth',
2122
'connect/react-native',
@@ -47,7 +48,7 @@ const sidebar = {
4748
label: "Create a wallet AI agent",
4849
href: "/tutorials/create-wallet-ai-agent"
4950
},
50-
{
51+
{
5152
type: "link",
5253
label: "Upgrade an EOA to a smart account",
5354
href: "/tutorials/upgrade-eoa-to-smart-account"
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
---
2+
description: Quickstart guide for using the MetaMask SDK with a JavaScript and RainbowKit dapp.
3+
toc_max_heading_level: 2
4+
sidebar_label: JavaScript + RainbowKit
5+
keywords: [connect, MetaMask, JavaScript, RainbowKit, SDK, dapp, Wallet SDK]
6+
---
7+
8+
# Connect to MetaMask using JavaScript + RainbowKit
9+
10+
Get started with MetaMask SDK in a JavaScript and RainbowKit dapp.
11+
You can [download the quickstart template](#set-up-using-a-template) or [manually set up the SDK](#set-up-manually) in an existing dapp.
12+
13+
<p align="center">
14+
<a href="https://metamask-rainbowkit-demo.vercel.app/" target="_blank">
15+
<img src={require("../_assets/quickstart.jpg").default} alt="Quickstart" width="600px" />
16+
</a>
17+
</p>
18+
19+
## Prerequisites
20+
21+
- [Node.js](https://nodejs.org/) version 19 or later installed.
22+
- A package manager installed, such as [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), [Yarn](https://yarnpkg.com/), [pnpm](https://pnpm.io/installation), or [bun](https://bun.sh/).
23+
- [MetaMask](https://metamask.io/) installed in your browser or on mobile.
24+
- A WalletConnect project ID from the [Reown dashboard](https://dashboard.reown.com/sign-in).
25+
26+
## Set up using a template
27+
28+
1. Download the [MetaMask SDK RainbowKit template](https://github.com/MetaMask/metamask-sdk-examples/tree/main/quickstarts/rainbowkit):
29+
30+
```bash
31+
npx degit MetaMask/metamask-sdk-examples/quickstarts/rainbowkit metamask-rainbowkit
32+
```
33+
34+
2. Navigate into the repository:
35+
36+
```bash
37+
cd metamask-rainbowkit
38+
```
39+
40+
<details>
41+
<summary>Degit vs. Git clone</summary>
42+
<div>
43+
44+
`degit` is a tool that enables cloning only the directory structure from a GitHub repository, without retrieving the entire repository.
45+
46+
Alternatively, you can use `git clone`, which will download the entire repository.
47+
To do so, clone the MetaMask SDK examples repository and navigate into the `quickstarts/rainbowkit` directory:
48+
49+
```bash
50+
git clone https://github.com/MetaMask/metamask-sdk-examples
51+
cd metamask-sdk-examples/quickstarts/rainbowkit
52+
```
53+
54+
</div>
55+
</details>
56+
57+
3. Install dependencies:
58+
59+
```bash
60+
pnpm install
61+
```
62+
63+
4. Create a `.env.local` file:
64+
65+
```bash
66+
touch .env.local
67+
```
68+
69+
5. In `.env.local`, add a `VITE_WALLETCONNECT_PROJECT_ID` environment variable, replacing `<YOUR-PROJECT-ID>` with your WalletConnect project ID:
70+
71+
```text title=".env.local"
72+
VITE_WALLETCONNECT_PROJECT_ID=<YOUR-PROJECT-ID>
73+
```
74+
75+
6. Run the project:
76+
77+
```bash
78+
pnpm dev
79+
```
80+
81+
## Set up manually
82+
83+
### 1. Install the SDK
84+
85+
Install MetaMask SDK along with its peer dependencies to an existing React project:
86+
87+
```bash npm2yarn
88+
npm install @rainbow-me/rainbowkit wagmi [email protected] @tanstack/react-query
89+
```
90+
91+
### 2. Import required dependencies
92+
93+
In the root of your project, import the required RainbowKit, Wagmi, and TanStack Query dependencies:
94+
95+
```jsx
96+
import "@rainbow-me/rainbowkit/styles.css"
97+
import { getDefaultConfig, RainbowKitProvider } from "@rainbow-me/rainbowkit"
98+
import { WagmiProvider } from "wagmi"
99+
import { metaMaskWallet } from "@rainbow-me/rainbowkit/wallets"
100+
import { mainnet, linea, sepolia, lineaSepolia } from "wagmi/chains"
101+
import { QueryClientProvider, QueryClient } from "@tanstack/react-query"
102+
```
103+
104+
### 3. Configure your project
105+
106+
Set up your configuration with the desired chains and wallets.
107+
In the following example, replace `<YOUR-PROJECT-ID>` with your WalletConnect project ID:
108+
109+
```jsx
110+
const config = getDefaultConfig({
111+
appName: "MetaMask SDK RainbowKit Quickstart",
112+
projectId: "<YOUR-PROJECT-ID>",
113+
chains: [mainnet, linea, sepolia, lineaSepolia],
114+
wallets: [
115+
{
116+
groupName: "Preferred",
117+
wallets: [metaMaskWallet],
118+
},
119+
],
120+
ssr: false, // true if your dapp uses server-side rendering.
121+
})
122+
```
123+
124+
### 4. Set up providers
125+
126+
Wrap your application with the `RainbowKitProvider`, `WagmiProvider`, and `QueryClientProvider` providers:
127+
128+
```jsx
129+
const queryClient = new QueryClient()
130+
131+
const App = () => {
132+
return (
133+
<WagmiProvider config={config}>
134+
<QueryClientProvider client={queryClient}>
135+
<RainbowKitProvider>
136+
<App />
137+
</RainbowKitProvider>
138+
</QueryClientProvider>
139+
</WagmiProvider>
140+
)
141+
}
142+
```
143+
144+
### 5. Add the connect button
145+
146+
Import and render the `ConnectButton` component:
147+
148+
```jsx
149+
import { ConnectButton } from "@rainbow-me/rainbowkit"
150+
151+
function App() {
152+
return <ConnectButton />
153+
}
154+
155+
export default App
156+
```
157+
158+
You can now test your dapp by running `pnpm run dev`.
159+
160+
## Live example
161+
162+
<iframe className="mt-6" width="100%" height="600px" frameBorder="0" src="https://stackblitz.com/github/MetaMask/metamask-sdk-examples/tree/main/quickstarts/rainbowkit?ctl=1&embed=1&file=src%2Fmain.tsx&hideNavigation=1"></iframe>

sdk/connect/javascript-wagmi.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ import { metaMask } from "wagmi/connectors"
8989
### 3. Configure your project
9090
9191
Set up your configuration with the desired chains and connectors.
92-
For example:
92+
In the following example, set the [`infuraAPIKey`](../reference/sdk-options.md#infuraapikey) option to your [Infura API key](/developer-tools/dashboard/get-started/create-api) to use for RPC requests:
9393
9494
```jsx
9595
const config = createConfig({
96-
ssr: true, // Make sure to enable this for server-side rendering (SSR) applications.
96+
ssr: true, // Enable this if your dapp uses server-side rendering.
9797
chains: [mainnet, linea, lineaSepolia],
9898
connectors: [
9999
metaMask({
@@ -163,7 +163,7 @@ For production deployments, it's important to use reliable RPC providers instead
163163
We recommend using services like [MetaMask Developer](https://developer.metamask.io/) to ensure better reliability and performance.
164164
:::
165165
166-
You can configure your RPC endpoints in the Wagmi configuration as follows:
166+
You can configure your RPC endpoints in the Wagmi configuration as follows, replacing `<YOUR-API-KEY>` with your [Infura API key](/developer-tools/dashboard/get-started/create-api):
167167
168168
```jsx
169169
const config = createConfig({
@@ -175,8 +175,6 @@ const config = createConfig({
175175
})
176176
```
177177
178-
Sign up to [MetaMask Developer](https://developer.metamask.io/) for a free account and get your API key.
179-
180178
## Next steps
181179
182180
After completing the basic setup, you can follow these guides to add your own functionality:

sdk/connect/javascript.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ You can [download the quickstart template](#set-up-using-a-template) or [manuall
2323
- [Node.js](https://nodejs.org/) version 19 or later installed.
2424
- A package manager installed, such as [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), [Yarn](https://yarnpkg.com/), [pnpm](https://pnpm.io/installation), or [bun](https://bun.sh/).
2525
- [MetaMask](https://metamask.io/) installed in your browser or on mobile.
26+
- An [Infura API key](/developer-tools/dashboard/get-started/create-api) from the MetaMask Developer dashboard.
2627

2728
## Set up using a template
2829

@@ -61,7 +62,19 @@ You can [download the quickstart template](#set-up-using-a-template) or [manuall
6162
pnpm install
6263
```
6364

64-
4. Run the project:
65+
4. Create a `.env.local` file:
66+
67+
```bash
68+
touch .env.local
69+
```
70+
71+
5. In `.env.local`, add a `VITE_INFURA_API_KEY` environment variable, replacing `<YOUR-API-KEY>` with your Infura API key:
72+
73+
```text title=".env.local"
74+
VITE_INFURA_API_KEY=<YOUR-API-KEY>
75+
```
76+
77+
6. Run the project:
6578

6679
```bash
6780
pnpm dev
@@ -124,8 +137,8 @@ const MMSDK = new MetaMaskSDK({
124137
These examples configure the SDK with the following options:
125138
126139
- [`dappMetadata`](../reference/sdk-options.md#dappmetadata) - Ensures trust by showing your dapp's `name`, `url`, and `iconUrl` during connection.
127-
128140
- [`infuraAPIKey`](../reference/sdk-options.md#infuraapikey) - Enables read-only RPC and load‑balancing.
141+
Set this option to your [Infura API key](/developer-tools/dashboard/get-started/create-api).
129142

130143
### 3. Connect and use provider
131144

0 commit comments

Comments
 (0)