Privy makes it easy to integrate cross-app wallets from various Privy apps into existing setups with RainbowKit, ConnectKit, wagmi and more using the @privy-io/cross-app-connect SDK.Integrating apps do not need to use Privy themselves to integrate cross-app wallets; instead, they can import a Privy cross-app connector directly from the SDK to configure with their wallet connector library. Simply follow the instructions below to get set up!
The sections below show the full integration steps. If the app already has RainbowKit configured, skip to step 2. Otherwise, follow all steps to set up RainbowKit from scratch.
If the app doesn’t use RainbowKit yet, follow steps 1-4 below to set up both RainbowKit and the global wallet connector together.If the app already has RainbowKit, skip to step 2 to just add the global wallet.
Import the toPrivyWallet connector function from @privy-io/cross-app-connect/rainbow-kit:
Report incorrect code
Copy
Ask AI
import {toPrivyWallet} from '@privy-io/cross-app-connect/rainbow-kit';
Use the toPrivyWallet method to create a wallet connector. The function takes id, name, and iconUrl (described below) and returns a connector that RainbowKit will use to connect to the provider wallet.
At the highest level of your applications, wrap the component with the wagmi, QueryClient, and RainbowKit providers. Pass the configuration you created in step 2 to the wagmi provider.
Report incorrect code
Copy
Ask AI
import {RainbowKitProvider} from '@rainbow-me/rainbowkit';import {QueryClient, QueryClientProvider} from '@tanstack/react-query';import type {AppProps} from 'next/app';import {WagmiProvider} from 'wagmi';import {config} from '../wagmi';const client = new QueryClient();function MyApp({Component, pageProps}: AppProps) { return ( <WagmiProvider config={config}> <QueryClientProvider client={client}> <RainbowKitProvider> <Component {...pageProps} /> </RainbowKitProvider> </QueryClientProvider> </WagmiProvider> );}export default MyApp;
Import the ConnectButton and use to prompt users to connect to their provider Privy wallet.
Report incorrect code
Copy
Ask AI
import {ConnectButton} from '@rainbow-me/rainbowkit';function Page() { return ( <div> <h1> My app </h1> ... <ConnectButton /> </div> );}
Thats it! You can now use any wagmi hook in your application to interact with the connected wallet. When users connect and transact with their wallet, Privy will open a pop-up for users to authorize any actions.