|
| 1 | +--- |
| 2 | +title: Migration from RainbowKit to AppKit |
| 3 | +--- |
| 4 | + |
| 5 | +# Migration from RainbowKit to AppKit |
| 6 | + |
| 7 | +Follow the steps below to migrate from the default Rainbowkit project using Next.js Pages to an Appkit project using wagmi. |
| 8 | + |
| 9 | +### step 1 . Create a project in WalletConnect Clouds |
| 10 | + |
| 11 | ++ Create a new project on WalletConnect Cloud at https://cloud.walletconnect.com and obtain a new project ID. |
| 12 | + |
| 13 | +### step 2 . Install & Uninstall libraries |
| 14 | + |
| 15 | ++ Run this command to install the `AppKit` Library and Uninstall the `RainbowKit` one. |
| 16 | + |
| 17 | +```bash |
| 18 | +pnpm install @web3modal/wagmi && pnpm uninstall @rainbow-me/rainbowkit |
| 19 | +``` |
| 20 | + |
| 21 | +### step 3 . Change the index.tsx |
| 22 | + |
| 23 | +Use the Appkit Button. It can be configure following these [guidelines](https://docs.walletconnect.com/appkit/react-native/core/components#w3mbutton-). |
| 24 | +```tsx |
| 25 | +/* highlight-delete-start */ |
| 26 | +- import { ConnectButton } from '@rainbow-me/rainbowkit'; |
| 27 | +/* highlight-delete-end */ |
| 28 | + |
| 29 | +/* highlight-delete-start */ |
| 30 | +- <ConnectButton /> |
| 31 | +/* highlight-delete-end */ |
| 32 | +/* highlight-add-start */ |
| 33 | ++ <w3m-button /> |
| 34 | +/* highlight-add-end */ |
| 35 | +``` |
| 36 | + |
| 37 | +:::info |
| 38 | +AppKit's web components are global html elements that don't require importing. |
| 39 | +::: |
| 40 | + |
| 41 | +### step 4 . Changes in your config file |
| 42 | + |
| 43 | ++ Replace the following import statements: |
| 44 | +```tsx |
| 45 | +/* highlight-delete-start */ |
| 46 | +- import { getDefaultConfig } from '@rainbow-me/rainbowkit'; |
| 47 | +/* highlight-delete-end */ |
| 48 | +/* highlight-add-start */ |
| 49 | ++ import { defaultWagmiConfig } from "@web3modal/wagmi/react/config"; |
| 50 | +/* highlight-add-end */ |
| 51 | +``` |
| 52 | + |
| 53 | ++ If you have something similar to this |
| 54 | +```tsx |
| 55 | +/* highlight-delete-start */ |
| 56 | +- export const config = getDefaultConfig({ |
| 57 | +- appName: 'RainbowKit App', |
| 58 | +- projectId: 'YOUR_PROJECT_ID', |
| 59 | +- chains: [ |
| 60 | +- mainnet, |
| 61 | +- polygon, |
| 62 | +- optimism, |
| 63 | +- arbitrum, |
| 64 | +- base, |
| 65 | +- ...(process.env.NEXT_PUBLIC_ENABLE_TESTNETS === 'true' ? [sepolia] : []), |
| 66 | +- ], |
| 67 | +- ssr: true, |
| 68 | +- }); |
| 69 | +/* highlight-delete-end */ |
| 70 | +``` |
| 71 | + |
| 72 | ++ Replace the wagmi config for this example. Also you can customize email and social logins following this [guidelines](https://docs.walletconnect.com/appkit/react/onboarding/socials). |
| 73 | + |
| 74 | +```tsx |
| 75 | +/* highlight-add-start */ |
| 76 | +export const projectId = "YOUR_PROJECT_ID"; |
| 77 | + |
| 78 | +export const metadata = { |
| 79 | + name: "AppKit App", |
| 80 | + description: "AppKit Example", |
| 81 | + url: "https://web3modal.com", // origin must match your domain and subdomain |
| 82 | + icons: ["https://avatars.githubusercontent.com/u/37784886"] |
| 83 | +}; |
| 84 | + |
| 85 | +// Create wagmiConfig |
| 86 | +export const config = defaultWagmiConfig({ |
| 87 | + chains, // chains are the same |
| 88 | + projectId, // Use the new Cloud Id |
| 89 | + metadata, |
| 90 | + auth: { |
| 91 | + email: true, |
| 92 | + socials: ["github", "google", "x", "discord", "apple"], |
| 93 | + showWallets: true, // default to true |
| 94 | + }, |
| 95 | + ssr: true, |
| 96 | +}); |
| 97 | +/* highlight-add-end */ |
| 98 | +``` |
| 99 | + |
| 100 | +### step 5 . Update app.tsx |
| 101 | + |
| 102 | +In this step, we'll update the import statements and remove the RainbowKitProvider from the component tree. |
| 103 | + |
| 104 | ++ Replace the following import statements: |
| 105 | +```tsx |
| 106 | +import '../styles/globals.css'; |
| 107 | +/* highlight-delete-start */ |
| 108 | +- import '@rainbow-me/rainbowkit/styles.css'; |
| 109 | +/* highlight-delete-end */ |
| 110 | +import type { AppProps } from 'next/app'; |
| 111 | +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; |
| 112 | +import { WagmiProvider } from 'wagmi'; |
| 113 | + |
| 114 | +/* highlight-delete-start */ |
| 115 | +- import { RainbowKitProvider } from '@rainbow-me/rainbowkit'; |
| 116 | +/* highlight-delete-end */ |
| 117 | +/* highlight-add-start */ |
| 118 | ++ import { createWeb3Modal } from "@web3modal/wagmi/react" |
| 119 | +/* highlight-add-end */ |
| 120 | + |
| 121 | +/* highlight-delete-start */ |
| 122 | +- import { config } from '../wagmi'; |
| 123 | +/* highlight-delete-end */ |
| 124 | +/* highlight-add-start */ |
| 125 | ++ import { config, metadata, projectId } from '../wagmi'; |
| 126 | +/* highlight-add-end */ |
| 127 | +``` |
| 128 | + |
| 129 | + |
| 130 | ++ Initialize the Web3Modal: |
| 131 | +```tsx |
| 132 | +const client = new QueryClient(); |
| 133 | + |
| 134 | +/* highlight-add-start */ |
| 135 | +// Create modal |
| 136 | +createWeb3Modal({ |
| 137 | + metadata, |
| 138 | + wagmiConfig: config, |
| 139 | + projectId, |
| 140 | + enableAnalytics: true, // Optional - defaults to your Cloud configuration |
| 141 | + enableOnramp: true, // Optional - false as default |
| 142 | +}); |
| 143 | +/* highlight-add-end */ |
| 144 | +``` |
| 145 | + |
| 146 | ++ Update the component: |
| 147 | +```tsx |
| 148 | +function MyApp({ Component, pageProps }: AppProps) { |
| 149 | + return ( |
| 150 | + <WagmiProvider config={config}> |
| 151 | + <QueryClientProvider client={client}> |
| 152 | +/* highlight-delete-start */ |
| 153 | +- <RainbowKitProvider> |
| 154 | +/* highlight-delete-end */ |
| 155 | + <Component {...pageProps} /> |
| 156 | +/* highlight-delete-start */ |
| 157 | +- </RainbowKitProvider> |
| 158 | +/* highlight-delete-end */ |
| 159 | + </QueryClientProvider> |
| 160 | + </WagmiProvider> |
| 161 | + ); |
| 162 | +} |
| 163 | + |
| 164 | +export default MyApp; |
| 165 | +``` |
| 166 | + |
| 167 | +### Final notes |
| 168 | + |
| 169 | ++ Ensure that you have updated all relevant configurations and imports in your project to reflect the changes from RainbowKit to AppKit. |
| 170 | ++ Test your application thoroughly to ensure that the migration has been successful and that all functionalities are working as expected. |
| 171 | ++ Check our [AppKit web examples](https://github.com/WalletConnect/web-examples/tree/main/dapps/web3modal) to compare with your implementation in case you are having issues |
0 commit comments