Integration steps
This guide assumes you have already integrated Privy into your app. If not, please begin with the Privy Quickstart.1. Install dependencies
Install the latest versions ofwagmi, @tanstack/react-query, @privy-io/react-auth, and @privy-io/wagmi:
2. Setup TanStack Query
To start, set up your app with the TanStack Query’s React Provider. Wagmi uses TanStack Query under the hood to power its data fetching and caching of wallet and blockchain data. To set up your app with TanStack Query, in the component where you render yourPrivyProvider, import the QueryClient class and the QueryClientProvider component from @tanstack/react-query:
QueryClient:
PrivyProvider, wrap your app’s components with the QueryClientProvider. This must be rendered inside the PrivyProvider component.
providers.tsx
client property of the QueryClientProvider, pass the queryClient instance you created.
3. Setup wagmi
Next, setup wagmi. This involves creating your wagmiconfig and wrapping your app with the WagmiProvider.
While completing the wagmi setup, make sure to import
createConfig and WagmiProvider from
@privy-io/wagmi. Do not import these from wagmi directly.Build your wagmi config
To build yourwagmi config, import the createConfig method from @privy-io/wagmi:
wagmiConfig.ts
createConfig, but ensures that the appropriate configuration options are set for the Privy integration. Specifically, it allows Privy to drive wagmi’s connectors state, enabling the two libraries to stay in sync.
Next, import your app’s required chains from viem/chains and the http transport from wagmi. Your app’s required chains should match whatever you configure as supportedChains for Privy.
createConfig with your imported chains and the http transport like so:
wagmiConfig.ts
Wrap your app with the WagmiProvider
Once you’ve built your wagmi config, in the same component where you render your PrivyProvider, import the WagmiProvider component from @privy-io/wagmi.
WagmiProvider, but ensures the necessary configuration properties for Privy are set. Specifically, it ensures that the reconnectOnMount prop is set to false, which is required for handling the embedded wallet. Wallets will still be automatically reconnected on mount.
Then, like the PrivyProvider, wrap your app’s components with the WagmiProvider. This must be rendered inside both the PrivyProvider and QueryClientProvider components.
providers.tsx
config property of the WagmiProvider, pass the config you created earlier.
Complete example
Altogether, this should look like:- providers.tsx
- wagmiConfig.ts
- privyConfig.ts
wagmi in your app! 🎉
4. Use wagmi throughout your app
Once you’ve completed the setup above, you can use wagmi’s React hooks throughout your app to interface with wallets and take read and write actions on the blockchain.
Using wagmi hooks
To use wagmi hooks, like useAccount, in your components, import the hook directly from wagmi and call it as usual:
Injected wallets, like the MetaMask browser extension, cannot be programmatically disconnected from your site; they can only be manually disconnected. In kind, Privy does not currently support programmatically disconnecting a wallet via wagmi’s
useDisconnect hook. This hook “shims” a disconnection, which can create discrepancies between what wallets are connected to an app vs. wagmi.Instead of disconnecting a given wallet, you can always prompt a user to connect a different wallet via the connectWallet method.When to use Privy vs. wagmi
Both Privy’s out-of-the-box interfaces and wagmi’s React hooks enable you to interface with wallets and to request signatures and transactions.
If your app integrates Privy alongside wagmi, you should:
- use Privy to connect external wallets and create embedded wallets
- use
wagmito take read or write actions from a connected wallet
Updating the active wallet
With Privy, users may have multiple wallets connected to your app, butwagmi’s React hooks return information for only one connected wallet at a time. This is referred to as the active wallet.
To update wagmi to return information for a different connected wallet, first import the useWallets hook from @privy-io/react-auth and the useSetActiveWallet hook from @privy-io/wagmi:
wallets array returned by useWallets
setActiveWallet method returned by the useSetActiveWallet hook:

