A minimal bare React Native example showing how to integrate MetaMask Embedded Wallets (Web3Auth) with email OTP login and interact with Ethereum using viem.
- Wrapping your app in
<Web3AuthProvider>(the new hooks-based API) - Logging in with email one-time password (
AUTH_CONNECTION.EMAIL_PASSWORDLESS) - Reading wallet address and balance via viem (
createWalletClient/createPublicClient) - Signing a message with
connection.ethereumProvider - Showing the Wallet Services UI overlay
- Enabling and managing MFA
- Logging out and clearing the session
| File | What it does |
|---|---|
web3authConfig.ts |
The only file you need to edit — Client ID, redirect URL, network, chain config |
lib/evm.ts |
Pure EVM helpers (getAddress, getBalance, signMessage) — no React, copy-paste friendly |
App.tsx |
<Web3AuthProvider> wrapper + HomeScreen component that uses all the hooks |
index.js |
Entry point — imports @web3auth/react-native-sdk/setup first (required for polyfills) |
metro.config.js |
Metro bundler config — wraps with withWeb3Auth() for Node.js polyfills |
- React Native
0.74.x(bare workflow) @web3auth/react-native-sdk^10.0.0— hooks API (useWeb3AuthConnect, etc.)viem^2.xreact-native-encrypted-storage(session persistence)@toruslabs/react-native-web-browser(OAuth in-app browser)@react-native-async-storage/async-storage^1.23.x(peer for@metamask/connect-multichainvia@web3auth/react-native-sdk)
- Node.js
>=18 - React Native CLI setup — follow the React Native CLI Quickstart
- Xcode (iOS) or Android Studio (Android)
- A Web3Auth Dashboard project
- Go to dashboard.web3auth.io and create a new project.
- Choose Sapphire Devnet for development or Sapphire Mainnet for production.
- Under Allowed Origins, add:
web3authrnexample://auth - Copy the Client ID and paste it into
web3authConfig.ts.
Critical: Sapphire Devnet and Mainnet produce different wallet addresses for the same user. Never switch networks in production.
git clone https://github.com/Web3Auth/web3auth-react-native-examples.git
cd web3auth-react-native-examples/rn-bare-quick-start
npm installcd ios && pod install && cd ..# Start Metro
npm start
# iOS (separate terminal)
npm run ios
# Android (separate terminal)
npm run androidconst web3AuthConfig: Web3AuthContextConfig = {
web3AuthOptions: {
clientId: "YOUR_CLIENT_ID",
redirectUrl: "web3authrnexample://auth",
network: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
chains: [{ chainNamespace: CHAIN_NAMESPACES.EIP155, chainId: "0xaa36a7", rpcTarget: "..." }],
defaultChainId: "0xaa36a7",
},
};<Web3AuthProvider webBrowser={WebBrowser} storage={EncryptedStorage} config={web3AuthConfig}>
<HomeScreen />
</Web3AuthProvider>const { connectTo } = useWeb3AuthConnect();
await connectTo({
authConnection: AUTH_CONNECTION.EMAIL_PASSWORDLESS,
extraLoginOptions: { login_hint: email },
});const { connection } = useWeb3Auth();
const provider = connection?.ethereumProvider;
if (!provider) return;
const address = await getAddress(provider);
const balance = await getBalance(provider);
const sig = await signMessage(provider, "Hello Web3Auth!");const { disconnect } = useWeb3AuthDisconnect();
await disconnect();index.js imports @web3auth/react-native-sdk/setup as the very first line — this seeds the crypto, Buffer, and URL polyfills that the SDK requires. metro.config.js uses withWeb3Auth() to alias Node.js built-ins for Metro.
Do not remove either — the SDK will fail to initialise without them.
Build errors after install
# Android
cd android && ./gradlew clean && cd ..
# iOS
cd ios && pod deintegrate && pod install && cd ..OAuth redirect not working — Verify the scheme in web3authConfig.ts matches the URL you added to the Dashboard. For Android, check AndroidManifest.xml; for iOS, check Info.plist.
Metro polyfill errors — See Metro Polyfill Troubleshooting.
@react-native-async-storage/async-storage not found — Install it explicitly: npm install @react-native-async-storage/async-storage@^1.23.1. Required by @metamask/connect-multichain (pulled in via @web3auth/react-native-sdk). After installing, run cd ios && pod install for iOS.
MIT — see LICENSE.