React Native
Introduction​
Web3Modal SDK has support for Wagmi v1 and Ethers v5. Choose one of these Ethereum libraries to get started.
Don't have a project ID?
Head over to WalletConnect Cloud and create a new project now!
Installation​
- React Native CLI
- Expo
- Wagmi v1
- Ethers v5
- npm
- Yarn
- Bun
- pnpm
npm install @web3modal/wagmi-react-native wagmi@1.4.13 viem@1.21.4
yarn add @web3modal/wagmi-react-native wagmi@1.4.13 viem@1.21.4
bun add @web3modal/wagmi-react-native wagmi@1.4.13 viem@1.21.4
pnpm add @web3modal/wagmi-react-native wagmi@1.4.13 viem@1.21.4
Additionally add these extra packages to help with async storage, polyfills, and SVG's.
- npm
- Yarn
- Bun
- pnpm
npm install @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat
yarn add @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat
bun add @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat
pnpm add @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat
On iOS, use CocoaPods to add the native modules to your project:
npx pod-install
Ethers v5 support is currently in alpha.
- npm
- Yarn
- Bun
- pnpm
npm install @web3modal/ethers5-react-native ethers@5.7.2
yarn add @web3modal/ethers5-react-native ethers@5.7.2
bun add @web3modal/ethers5-react-native ethers@5.7.2
pnpm add @web3modal/ethers5-react-native ethers@5.7.2
Additionally add these extra packages to help with async storage, polyfills, and SVG's.
- npm
- Yarn
- Bun
- pnpm
npm install @ethersproject/shims@5.7.0 @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat
yarn add @ethersproject/shims@5.7.0 @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat
bun add @ethersproject/shims@5.7.0 @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat
pnpm add @ethersproject/shims@5.7.0 @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat
On iOS, use CocoaPods to add the native modules to your project:
npx pod-install
- Wagmi v1
- Ethers v5
npx expo install @web3modal/wagmi-react-native wagmi@1.4.13 viem@1.21.4
Additionally add these extra packages to help with async storage, polyfills, and SVG's.
npx expo install @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat expo-application
Additional setup for Expo SDK 48 only
If you are using Expo SDK 48, you also need to polyfill crypto
with expo-crypto library.
- Add
expo-crypto
npx expo install expo-crypto
- Create a file named
crypto-polyfill.js
// src/crypto-polyfill.js
// Apply only with Expo SDK 48
import { getRandomValues as expoCryptoGetRandomValues } from 'expo-crypto'
class Crypto {
getRandomValues = expoCryptoGetRandomValues
}
// eslint-disable-next-line no-undef
const webCrypto = typeof crypto !== 'undefined' ? crypto : new Crypto()
;(() => {
if (typeof crypto === 'undefined') {
Object.defineProperty(window, 'crypto', {
configurable: true,
enumerable: true,
get: () => webCrypto
})
}
})()
- Import
crypto-polyfill.js
in your App root file
// src/App.js
import './crypto-polyfill.js'
import '@walletconnect/react-native-compat';
...
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi-react-native'
Ethers v5 support is currently in alpha.
npx expo install @web3modal/ethers5-react-native ethers@5.7.2
Additionally add these extra packages to help with async storage, polyfills, and SVG's.
npx expo install @ethersproject/shims@5.7.0 @react-native-async-storage/async-storage react-native-get-random-values react-native-svg react-native-modal @react-native-community/netinfo @walletconnect/react-native-compat expo-application
Additional setup for Expo SDK 48 only
If you are using Expo SDK 48, you also need to polyfill crypto
with expo-crypto library.
- Add
expo-crypto
npx expo install expo-crypto
- Create a file named
crypto-polyfill.js
// src/crypto-polyfill.js
// Apply only with Expo SDK 48
import { getRandomValues as expoCryptoGetRandomValues } from 'expo-crypto'
class Crypto {
getRandomValues = expoCryptoGetRandomValues
}
// eslint-disable-next-line no-undef
const webCrypto = typeof crypto !== 'undefined' ? crypto : new Crypto()
;(() => {
if (typeof crypto === 'undefined') {
Object.defineProperty(window, 'crypto', {
configurable: true,
enumerable: true,
get: () => webCrypto
})
}
})()
- Import
crypto-polyfill.js
in your App root file
// src/App.js
import './crypto-polyfill.js'
import '@walletconnect/react-native-compat';
...
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi-react-native'
Implementation​
- Wagmi v1
- Ethers v5
Start by importing createWeb3Modal
, and wagmi packages, then create your configs as shown below.
Finally, pass your configuration to createWeb3Modal
.
Make sure you import @walletconnect/react-native-compat
before wagmi
to avoid any issues.
import '@walletconnect/react-native-compat'
import { WagmiConfig } from 'wagmi'
import { mainnet, polygon, arbitrum } from 'viem/chains'
import { createWeb3Modal, defaultWagmiConfig, Web3Modal } from '@web3modal/wagmi-react-native'
// 1. Get projectId at https://cloud.walletconnect.com
const projectId = 'YOUR_PROJECT_ID'
// 2. Create config
const metadata = {
name: 'Web3Modal RN',
description: 'Web3Modal RN Example',
url: 'https://web3modal.com',
icons: ['https://avatars.githubusercontent.com/u/37784886'],
redirect: {
native: 'YOUR_APP_SCHEME://',
universal: 'YOUR_APP_UNIVERSAL_LINK.com'
}
}
const chains = [mainnet, polygon, arbitrum]
const wagmiConfig = defaultWagmiConfig({ chains, projectId, metadata })
// 3. Create modal
createWeb3Modal({
projectId,
chains,
wagmiConfig
})
export default function App() {
return (
<WagmiConfig config={wagmiConfig}>
// Rest of your app...
<Web3Modal />
</WagmiConfig>
)
}
Trigger the modal​
To open Web3Modal you can use our default button component or build your own logic using Web3Modal hooks.
- Components
- Hooks
You can use default components to open the modal
import { W3mButton } from '@web3modal/wagmi-react-native'
export default function ConnectView() {
return (
<>
...rest of your view
<W3mButton />
</>
)
}
Learn more about the Web3Modal components here
You can trigger the modal by calling the open
function from useWeb3Modal
hook.
import { Pressable, Text } from 'react-native'
import { useWeb3Modal } from '@web3modal/wagmi-react-native'
export default function ConnectView() {
const { open } = useWeb3Modal()
return (
<>
<Pressable onClick={() => open()}>
<Text>Open Connect Modal</Text>
</Pressable>
</>
)
}
Learn more about the Web3Modal hooks here
Start by importing createWeb3Modal
, and wagmi packages, then create your configs as shown below.
Finally, pass your configuration to createWeb3Modal
.
Make sure you import @walletconnect/react-native-compat
and @ethersproject/shims
before using our package to avoid any issues.
import '@walletconnect/react-native-compat'
import '@ethersproject/shims'
import { createWeb3Modal, defaultConfig, Web3Modal } from '@web3modal/ethers5-react-native'
// 1. Get projectId at https://cloud.walletconnect.com
const projectId = 'YOUR_PROJECT_ID'
// 2. Create config
const metadata = {
name: 'Web3Modal RN',
description: 'Web3Modal RN Example',
url: 'https://web3modal.com',
icons: ['https://avatars.githubusercontent.com/u/37784886'],
redirect: {
native: 'YOUR_APP_SCHEME://',
}
}
const config = defaultConfig({ metadata });
// 3. Define your chains
const mainnet = {
chainId: 1,
name: 'Ethereum',
currency: 'ETH',
explorerUrl: 'https://etherscan.io',
rpcUrl: 'https://cloudflare-eth.com',
};
const polygon = {
chainId: 137,
name: 'Polygon',
currency: 'MATIC',
explorerUrl: 'https://polygonscan.com',
rpcUrl: 'https://polygon-rpc.com',
};
const chains = [mainnet, polygon];
// 3. Create modal
createWeb3Modal({
projectId,
chains,
config
})
export default function App() {
return (
<>
// Rest of your app...
<Web3Modal />
</>
)
}
Trigger the modal​
To open Web3Modal you can use our default button component or build your own logic using Web3Modal hooks.
- Components
- Hooks
You can use default components to open the modal
import { W3mButton } from '@web3modal/ethers5-react-native'
export default function ConnectView() {
return (
<>
...rest of your view
<W3mButton />
</>
)
}
Learn more about the Web3Modal components here
You can trigger the modal by calling the open
function from useWeb3Modal
hook.
import { Pressable, Text } from 'react-native'
import { useWeb3Modal } from '@web3modal/ethers5-react-native'
export default function ConnectView() {
const { open } = useWeb3Modal()
return (
<>
<Pressable onClick={() => open()}>
<Text>Open Connect Modal</Text>
</Pressable>
</>
)
}
Learn more about the Web3Modal hooks here
Enable Wallet Detection​
Make sure your have @walletconnect/react-native-compat@2.10.5
or higher.
To enable WalletConnectModal to detect wallets installed on the device, you need to make specific changes to the native code of your project.
- React Native CLI
- Expo
For iOS:​
- Open your
Info.plist
file. - Locate the
<key>LSApplicationQueriesSchemes</key>
section. - Add the desired wallet schemes as string entries within the
<array>
. These schemes represent the wallets you want to detect. - Refer to our Info.plist example file for a detailed illustration.
Example:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>metamask</string>
<string>trust</string>
<string>safe</string>
<string>rainbow</string>
<string>uniswap</string>
<!-- Add other wallet schemes names here -->
</array>
For Android:​
- Open your
AndroidManifest.xml
file. - Locate the
<queries>
section. - Add the desired wallet package names as
<package>
entries within the<queries>
. These package names correspond to the wallets you want to detect. - Refer to our AndroidManifest.xml example file for detailed guidance.
Example:
<queries>
<package android:name="io.metamask"/>
<package android:name="com.wallet.crypto.trustapp"/>
<package android:name="io.gnosis.safe"/>
<package android:name="me.rainbow"/>
<!-- Add other wallet package names here -->
</queries>
For iOS only:​
To enable WalletConnectModal to detect wallets installed on the device in your Expo project for iOS, follow these steps:
- Open your
app.json
(orapp.config.js
) file. - Locate the ios section within the configuration.
- Add the
infoPlist
object if it doesn't exist, and within it, include theLSApplicationQueriesSchemes
array. This array will contain the desired wallet schemes you want to detect. - Add the wallet schemes to the
LSApplicationQueriesSchemes
array.
Your configuration should look like this:
{
"expo": {
"ios": {
"infoPlist": {
"LSApplicationQueriesSchemes": [
"metamask",
"trust",
"safe",
"rainbow",
"uniswap"
// Add other wallet schemes names here
]
}
}
}
}
Enable Coinbase Wallet​
- React Native CLI
- Expo
Follow these steps to install Coinbase SDK in your project along with our custom Wagmi connector. Check here for more detailed information.
- Note: Coinbase SDK is not compatible with Expo Go
-
Enable Expo Modules in your project running:
npx install-expo-modules@latest
-
Install Coinbase SDK
- npm
- Yarn
- Bun
- pnpm
npm install @coinbase/wallet-mobile-sdk react-native-mmkv
yarn add @coinbase/wallet-mobile-sdk react-native-mmkv
bun add @coinbase/wallet-mobile-sdk react-native-mmkv
pnpm add @coinbase/wallet-mobile-sdk react-native-mmkv
- Install our custom connector
- Wagmi v1
- Ethers v5
- npm
- Yarn
- Bun
- pnpm
npm install @web3modal/coinbase-wagmi-react-native
yarn add @web3modal/coinbase-wagmi-react-native
bun add @web3modal/coinbase-wagmi-react-native
pnpm add @web3modal/coinbase-wagmi-react-native
- npm
- Yarn
- Bun
- pnpm
npm install @web3modal/coinbase-ethers-react-native
yarn add @web3modal/coinbase-ethers-react-native
bun add @web3modal/coinbase-ethers-react-native
pnpm add @web3modal/coinbase-ethers-react-native
- Run pod-install
npx pod-install
-
Enable Deeplink handling in your project following React Native docs
-
Add Coinbase package in your AndroidManifest.xml and Info.Plist
// AndroidManifest.xml
<queries>
<!-- other queries -->
<package android:name="org.toshi" />
</queries>
// Info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- other schemes -->
<string>cbwallet</string>
</array>
- Add Coinbase reponse handler in your app. More info here
import { handleResponse } from '@coinbase/wallet-mobile-sdk'
// Your app's deeplink handling code
useEffect(() => {
const sub = Linking.addEventListener('url', ({ url }) => {
const handledBySdk = handleResponse(new URL(url))
if (!handledBySdk) {
// Handle other deeplinks
}
})
return () => sub.remove()
}, [])
- Initialize
CoinbaseWagmiConnector
and add it inextraConnectors
- Wagmi v1
- Ethers v5
import { CoinbaseConnector } from '@web3modal/coinbase-wagmi-react-native'
const coinbaseConnector = new CoinbaseConnector({
chains,
options: {
redirect: 'YOUR_APP_SCHEME://'
}
})
const wagmiConfig = defaultWagmiConfig({
chains,
projectId,
metadata,
extraConnectors: [coinbaseConnector]
})
import { CoinbaseProvider } from '@web3modal/coinbase-ethers-react-native'
const coinbaseProvider = new CoinbaseProvider({
redirect: 'YOUR_APP_SCHEME://',
rpcUrl: mainnet.rpcUrl,
})
const config = defaultConfig({
metadata,
coinbase: coinbaseProvider,
})
Check Coinbase docs for more detailed information.
Coinbase SDK doesn't support Expo Projects. More info here
Was this helpful?