| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Web3Auth is where passwordless auth meets non-custodial key infrastructure for Web3 apps and wallets. By aggregating OAuth (Google, Twitter, Discord) logins, different wallets and innovative Multi Party Computation (MPC) - Web3Auth provides a seamless login experience to every user on your application.
Checkout the official Web3Auth Documentation and SDK Reference to get started!
...and a lot more
In React Native, you have the choice to use one of the following workflows:
npm install @web3auth/react-native-sdkInstall the workflow-specific browser and secure storage packages next.
npm install @toruslabs/react-native-web-browser react-native-encrypted-storage
npm install --save-optional react-native-quick-cryptonpx expo install expo-web-browser expo-secure-store expo-linking expo-constants
npm install --save-optional react-native-quick-cryptoreact-native-quick-crypto is optional but recommended. Without it, Metro falls back to crypto-browserify.
Web3Auth requires Metro polyfills and a setup import before any other app code.
Wrap your Metro config with withWeb3Auth:
Bare
const { getDefaultConfig } = require("@react-native/metro-config");
const { withWeb3Auth } = require("@web3auth/react-native-sdk/metro-config");
const config = getDefaultConfig(__dirname);
module.exports = withWeb3Auth(config);Expo
const { getDefaultConfig } = require("expo/metro-config");
const { withWeb3Auth } = require("@web3auth/react-native-sdk/metro-config");
const config = getDefaultConfig(__dirname);
module.exports = withWeb3Auth(config);Import the setup module first in your root entry file (index.js / index.ts):
import "@web3auth/react-native-sdk/setup";
// ... rest of your app entryHop on to the Web3Auth Dashboard and create a new project. Use the Client ID of the project to start your integration.
The scheme portion of redirectUrl must be registered in AndroidManifest.xml so the auth browser can return to your app.
Inside your MainActivity, add a browsable deep-link intent filter:
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:exported="true">
<!-- existing MAIN/LAUNCHER intent-filter -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="web3authrnexample" />
</intent-filter>
</activity>Replace web3authrnexample with the scheme used in your redirectUrl.
Register the same scheme in your iOS Info.plist via CFBundleURLTypes:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>web3authrnexample</string>
<key>CFBundleURLSchemes</key>
<array>
<string>web3authrnexample</string>
</array>
</dict>
</array>When using Expo, install the Expo browser/storage packages (see Installation) and declare a scheme in app.json:
{
"expo": {
"scheme": "web3authexpoexample"
}
}Derive redirectUrl with expo-linking. Expo Go and standalone/dev-client builds produce different URLs — whitelist both in the dashboard:
import Constants, { AppOwnership } from "expo-constants";
import * as Linking from "expo-linking";
const redirectUrl =
Constants.appOwnership === AppOwnership.Expo || Constants.appOwnership === AppOwnership.Guest
? Linking.createURL("web3auth", {})
: Linking.createURL("web3auth", { scheme: "web3authexpoexample" });Standalone builds resolve to a URL like web3authexpoexample://web3auth. Expo Go resolves to an exp://…/--/web3auth URL for your current session.
Whitelist the literal redirectUrl string your app passes to the SDK:
| Workflow | Example redirectUrl |
|---|---|
| Bare | web3authrnexample://auth |
| Expo standalone / dev client | web3authexpoexample://web3auth |
| Expo Go | output of Linking.createURL("web3auth", {}) |
The SDK sends anonymous usage events to Segment so Web3Auth can improve reliability and feature coverage.
What is tracked (SDK-observable events):
Not tracked from React Native today:
Defaults and controls:
| Option | Default | Behavior |
|---|---|---|
| (none) | — | Analytics enabled; uses the production Segment write key |
| buildEnv: DEVELOPMENT | PRODUCTION | Uses the development Segment write key |
| disableAnalytics: true | false | Suppress all identify/track calls |
const web3auth = new Web3Auth(WebBrowser, EncryptedStorage, {
clientId,
network: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
redirectUrl: "web3authrnexample://auth",
// buildEnv: BUILD_ENV.DEVELOPMENT, // QA only; uses the development Segment write key
// disableAnalytics: true, // full opt-out
});When using Web3AuthProvider, integration_type is set to "React Hooks". Direct new Web3Auth(...) usage reports "Native SDK".
Optional Wagmi 3 integration is available from @web3auth/react-native-sdk/wagmi. It derives EIP-155 chains from your Web3Auth config and bridges connection.ethereumProvider into Wagmi through a React Native-safe connector (no window / injected discovery).
Install peers:
npm install wagmi@^3 @wagmi/core@^3 viem@^2 @tanstack/react-query@^5Nest providers in this order. Keep your own QueryClientProvider; the SDK does not create one:
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Web3AuthProvider } from "@web3auth/react-native-sdk";
import { WagmiProvider } from "@web3auth/react-native-sdk/wagmi";
import { createStorage } from "wagmi";
import AsyncStorage from "@react-native-async-storage/async-storage";
const queryClient = new QueryClient();
const storage = createStorage({
storage: {
getItem: async (key) => AsyncStorage.getItem(key),
setItem: async (key, value) => {
await AsyncStorage.setItem(key, value);
},
removeItem: async (key) => {
await AsyncStorage.removeItem(key);
},
},
});
<QueryClientProvider client={queryClient}>
<Web3AuthProvider webBrowser={...} storage={...} config={...}>
<WagmiProvider config={{ storage }}>
<App />
</WagmiProvider>
</Web3AuthProvider>
</QueryClientProvider>Notes:
// babel.config.js
module.exports = function (api) {
api.cache(true);
return {
presets: [
[
"babel-preset-expo",
{
unstable_transformProfile: "hermes-v0",
unstable_transformImportMeta: true,
},
],
],
};
};See demo/rn-expo-hooks-example for a complete Expo example.
Optional Solana Framework Kit integration is available from @web3auth/react-native-sdk/solana. It bridges the Auth Solana wallet into @solana/react-hooks through SolanaProvider.
Install peers:
npm install @solana/react-hooks@^1.4.0Nest SolanaProvider under Web3AuthProvider:
import { Web3AuthProvider } from "@web3auth/react-native-sdk";
import { SolanaProvider } from "@web3auth/react-native-sdk/solana";
<Web3AuthProvider webBrowser={...} storage={...} config={...}>
<SolanaProvider>
<App />
</SolanaProvider>
</Web3AuthProvider>Notes:
Create a Web3Auth instance with your browser adapter, secure storage adapter, and project options. Call init() before connectTo().
import "@web3auth/react-native-sdk/setup";
import * as WebBrowser from "@toruslabs/react-native-web-browser";
import Web3Auth, { AUTH_CONNECTION, WEB3AUTH_NETWORK } from "@web3auth/react-native-sdk";
import EncryptedStorage from "react-native-encrypted-storage";
const scheme = "web3authrnexample";
const redirectUrl = `${scheme}://auth`;
const web3auth = new Web3Auth(WebBrowser, EncryptedStorage, {
clientId,
network: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
redirectUrl,
});
await web3auth.init();
await web3auth.connectTo({
authConnection: AUTH_CONNECTION.GOOGLE,
});import "@web3auth/react-native-sdk/setup";
import Web3Auth, { AUTH_CONNECTION, WEB3AUTH_NETWORK } from "@web3auth/react-native-sdk";
import Constants, { AppOwnership } from "expo-constants";
import * as Linking from "expo-linking";
import * as SecureStore from "expo-secure-store";
import * as WebBrowser from "expo-web-browser";
const redirectUrl =
Constants.appOwnership === AppOwnership.Expo || Constants.appOwnership === AppOwnership.Guest
? Linking.createURL("web3auth", {})
: Linking.createURL("web3auth", { scheme: "web3authexpoexample" });
const web3auth = new Web3Auth(WebBrowser, SecureStore, {
clientId,
network: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
redirectUrl,
});
await web3auth.init();
await web3auth.connectTo({
authConnection: AUTH_CONNECTION.GOOGLE,
});Checkout the examples for your preferred blockchain and platform in our examples
Checkout the Web3Auth Demo to see how Web3Auth can be used in an application.
Further checkout the demo folder within this repository, which contains sample bare and Expo apps.
| Back | FazBrowse Home | New Git URL |