Upgrade Guide
Web3Modal v5 to Reown Web AppKit | Ethers
This guide will help you migrate from Web3Modal v5 using ethers to the latest Reown AppKit.
Find here all the upgrades guides:
- To Reown Web AppKit using Wagmi.
- To Reown Web AppKit using Solana.
- To Reown Web AppKit using Ethers v5.
Installation
To upgrade from Web3Modal v5 to Reown AppKit, start by removing the Web3Modal v5 dependency @web3modal/ethers
.
- npm
- Yarn
- Bun
- pnpm
npm uninstall @web3modal/ethers
yarn remove @web3modal/ethers
npm uninstall @web3modal/ethers
pnpm remove @web3modal/ethers
Next, install the Reown AppKit packages.
- npm
- Yarn
- Bun
- pnpm
npm install @reown/appkit @reown/appkit-adapter-ethers
yarn add @reown/appkit @reown/appkit-adapter-ethers
bun add @reown/appkit @reown/appkit-adapter-ethers
pnpm add @reown/appkit @reown/appkit-adapter-ethers
Implementation
- React
- Vue
- JavaScript
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 WalletConnect's provider.
Make sure to set your configuration outside React components to avoid unwanted rerenders.
Start by importing createAppKit
from @reown/appkit
and the necessary chains from @reown/appkit/networks
- import { createWeb3Modal, defaultConfig } from '@web3modal/ethers/react'
- import { arbitrum, mainnet } from 'viem/chains'
+ import { createAppKit } from '@reown/appkit/react'
+ import { arbitrum, mainnet } from '@reown/appkit/networks'
+ import { EthersAdapter } from '@reown/appkit-adapter-ethers'
Then, remove the defaultConfig
function that is being imported from the Ethers package in your code.
const projectId = 'YOUR_PROJECT_ID'
const queryClient = new QueryClient()
const metadata = { //optional
name: 'AppKit',
description: 'AppKit Example',
url: 'https://example.com',
icons: ['https://avatars.githubusercontent.com/u/179229932']
}
+ const ethersConfig = defaultConfig({ ... })
Finally, set up the EthersAdapter
and pass the other parameters to createAppKit
function.
- createWeb3Modal({ ethersConfig, projectId, chains })
// import { createAppKit } from '@reown/appkit/react'
+ createAppKit({
adapters: [new EthersAdapter()],
networks: [mainnet, arbitrum],
metadata,
projectId,
features: {
analytics: true,
}
})
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 WalletConnect's provider.
Make sure to set your configuration outside React components to avoid unwanted rerenders.
Start by importing createAppKit
from @reown/appkit
and the necessary chains from @reown/appkit/networks
import { createWeb3Modal, defaultConfig } from '@web3modal/ethers/vue'
import { createAppKit } from '@reown/appkit/vue'
import { arbitrum, mainnet } from '@reown/appkit/networks'
import { EthersAdapter } from '@reown/appkit-adapter-ethers'
Then, remove the defaultConfig
function that is being imported from the Ethers package in your code.
const projectId = 'YOUR_PROJECT_ID'
const queryClient = new QueryClient()
const metadata = { //optional
name: 'AppKit',
description: 'AppKit Example',
url: 'https://example.com',
icons: ['https://avatars.githubusercontent.com/u/179229932']
}
- const ethersConfig = defaultConfig({ ... })
Finally, set up the EthersAdapter
and pass the other parameters to createAppKit
function.
- createWeb3Modal({ ethersConfig, projectId, chains })
// import { createAppKit } from '@reown/appkit/vue'
// import { EthersAdapter } from '@reown/appkit-adapter-ethers'
+ const modal = createAppKit({
adapters: [new EthersAdapter()],
networks: [mainnet, arbitrum],
metadata,
projectId,
features: {
analytics: true,
}
})
Start by importing AppKit packages, then create EthersAdapter using your own settings or the default presets as shown below.
Import createAppKit
from @reown/appkit
and the necessary chains from @reown/appkit/networks
import { createWeb3Modal, defaultConfig } from '@web3modal/ethers'
+ import { createAppKit } from '@reown/appkit'
+ import { arbitrum, mainnet } from '@reown/appkit/networks'
+ import { EthersAdapter } from '@reown/appkit-adapter-ethers'
Then, remove the defaultConfig
function that is being imported from the Ethers package in your code.
const projectId = 'YOUR_PROJECT_ID'
const queryClient = new QueryClient()
const metadata = { //optional
name: 'AppKit',
description: 'AppKit Example',
url: 'https://example.com',
icons: ['https://avatars.githubusercontent.com/u/179229932']
}
/* Remove the existing Ethers Config */
- const ethersConfig = defaultConfig({ ... })
Finally, set up the EthersAdapter
and pass the other parameters to createAppKit
function.
- const modal = createWeb3Modal({
ethersConfig,
projectId,
enableAnalytics: true
})
// import { createAppKit } from '@reown/appkit'
+ const modal = createAppKit({
adapters: [new EthersAdapter()],
networks: [mainnet, arbitrum],
metadata,
projectId,
features: {
analytics: true
}
})
Trigger the modal
- React
- Vue
- JavaScript
- import { useWeb3Modal } from '@web3modal/ethers/react'
+ import { useAppKit } from '@reown/appkit/react'
function HomePage() {
const { open } = useAppKit()
return <button onClick={open}>Connect</button>
}
Learn more about Reown AppKit here
Use your own button to open the modal
document.getElementById('my-button').addEventListener('click', () => {
modal.open()
})
<button id="my-button">Connect Wallet</button>
Learn more about Reown AppKit JavaScript here
Use your own button to open the modal
document.getElementById('my-button').addEventListener('click', () => {
modal.open()
})
<button id="my-button">Connect Wallet</button>
Learn more about Reown AppKit JavaScript here
Properties
As you may have noticed, some of the properties of Web3Modal have changed as a consequence of the migration to Reown AppKit.
adapters
The adapters
property is a new property that is an array of adapters that can be initialized.
networks
The chains
property is now networks
in Reown AppKit. You should import them from @reown/appkit/networks
package instead of importing these networks from viem
or other packages.
defaultNetwork
The defaultChain
property is now defaultNetwork
in Reown AppKit. This is a network object that specifies the default network for your Web3 app.
Utility Functions
The following methods are still available with the same nomenclature as before:
modal.getAddress()
This returns the connected address.
It returns the active namespace's address.
Example: You’ve initialized both the Wagmi and Solana adapters and connected to a dApp with an EVM-only wallet (e.g., Rainbow). In this case, the Solana adapter is still not connected. When your active network is one of the EVM chains, the address will return your wallet address. However, if you manually switch to the Solana network, the address will return undefined
(unless you connect to a Solana wallet).
modal.getError()
This returns the error values.
modal.getChainId()
Returns the active network's chainId
In versions prior to v5, which were single-chain, getChainId()
returned a single type rather than multiple types:
@web3modal/wagmi
(along with ethers and ethers5) returnednumber | undefined
.@web3modal/solana
returnedstring | undefined
.
Now, in Reown AppKit, since both chains can be connected simultaneously, the type definition is number | string | undefined
.