useWeb3Auth
Core hook that exposes the SDK state, the active wallet connection, and the underlying Web3Auth
instance. Use it to check whether the user is signed in and to read the EVM provider or Solana
wallet after sign-in.
Import
import { useWeb3Auth } from '@web3auth/react-native-sdk'
Usage
import { useWeb3Auth } from '@web3auth/react-native-sdk'
import { ActivityIndicator, Text } from 'react-native'
import { createWalletClient, custom } from 'viem'
function HomeView() {
const { isConnected, isInitializing, initError, connection } = useWeb3Auth()
if (isInitializing) return <ActivityIndicator />
if (initError) return <Text>{String(initError)}</Text>
if (!isConnected) return <Text>Please sign in</Text>
const getEvmAddress = async () => {
const walletClient = createWalletClient({
transport: custom(connection!.ethereumProvider!),
})
const [address] = await walletClient.getAddresses()
return address
}
// ...
}
connection only after sign-inconnection is null until the user connects. Check isConnected before you read
connection.ethereumProvider or connection.solanaWallet, for example, inside an event handler or
after an early return.
Return type
import { type IUseWeb3Auth } from '@web3auth/react-native-sdk'
connection
Connection | null
Active wallet connection after sign-in, or null when signed out. Contains:
ethereumProvider: EIP-1193 provider for EVM chains. Pass it to viem (custom(ethereumProvider)) or ethers (new ethers.BrowserProvider(ethereumProvider)).nullwhen the active chain is Solana.solanaWallet: Wallet Standard wallet for Solana chains.nullwhen the active chain is EVM. Use it through the Solana hooks.connectorName: Name of the connector (auth).connectorNamespace:eip155orsolana.
isConnected
boolean
true when the user has an active session.
isAuthorized
boolean
true when the session has an Embedded Wallets access token. Sessions created by passing an
idToken to connectTo are connected but not authorized.
accessToken
string | null
Current Embedded Wallets access token, or null. Use useAccessToken to
fetch a fresh value.
isInitialized
boolean
true after the SDK finishes initialization.
isInitializing
boolean
true while the provider initializes the SDK and restores any previous session. Render a loading
state while this is true to avoid a flash of the signed-out screen.
initError
unknown
Error thrown during initialization, or null. For example, initialization fails if no chains are
configured on the dashboard or in web3AuthOptions.chains.
web3Auth
Web3Auth | null
The underlying SDK instance. Useful for read-only state such as web3Auth.currentChain,
web3Auth.currentChainId, and web3Auth.configuredChains. Prefer the dedicated hooks for actions.