Skip to main content

Upgrade Guide

AppKit v2 to AppKit v5 Upgrade Guide

This guide is useful for those that have used a previous AppKit V2 version and are looking to upgrade to AppKit v5.

Installation

To upgrade from AppKit v2 to AppKit v4 start by removing AppKit v2 dependencies @web3modal/ethereum and @web3modal/react. Now you can install AppKit library and update Wagmi and Viem.

npm install @web3modal/wagmi@latest wagmi@2.x viem@2.x @tanstack/react-query@5.x

Implementation

You can start the AppKit configuration by using either the default or advanced mode.

Default mode will implement WalletConnect, Browser Wallets (injected) and Coinbase options in addition to Wagmi's public clients and WalletConnect's provider.

note

Make sure to set your configuration outside React components to avoid unwanted rerenders.

Start by importing createWeb3Modal, defaultWagmiConfig and wagmi packages

- import { EthereumClient, w3mConnectors, w3mProvider } from '@web3modal/ethereum'
- import { Web3Modal } from '@web3modal/react'
+ import { createWeb3Modal } from '@web3modal/wagmi/react'
+ import { defaultWagmiConfig } from '@web3modal/wagmi/react/config'
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'

import { WagmiConfig } from 'wagmi'
import { arbitrum, mainnet } from 'viem/chains'

Then create wagmiConfig using defaultWagmiConfig function as shown below

const chains = [arbitrum, mainnet]
const projectId = 'YOUR_PROJECT_ID'

/* Create Wagmi Config */
- const { publicClient } = configureChains(chains, [w3mProvider({ projectId })])
- const wagmiConfig = createConfig({
- autoConnect: true,
- connectors: w3mConnectors({ projectId, chains }),
- publicClient
- })
+ const queryClient = new QueryClient()

+ const metadata = {
+ name: 'AppKit',
+ description: 'AppKit Example',
+ url: 'https://web3modal.com',
+ icons: ['https://avatars.githubusercontent.com/u/37784886']
+ }

+ const wagmiConfig = defaultWagmiConfig({ chains, projectId, metadata })

Finally, pass config to createWeb3Modal

/* Call createWeb3Modal function */
- const ethereumClient = new EthereumClient(wagmiConfig, chains)
+ createWeb3Modal({ wagmiConfig, projectId, chains })

export default function App() {
return (
<>
<WagmiConfig config={wagmiConfig}>
+ <QueryClientProvider client={queryClient}>
<HomePage />
+ </QueryClientProvider>
</WagmiConfig>

- <Web3Modal projectId={projectId} ethereumClient={ethereumClient} />
</>
)
}

Trigger the modal

- import { useWeb3Modal } from '@web3modal/react'
+ import { useWeb3Modal } from '@web3modal/wagmi/react'

function HomePage() {
const { open } = useWeb3Modal()

return <button onClick={() => open()}>Connect</button>
}

Learn more about AppKit v4 here