For AI agents: a documentation index is available at /llms.txt. A markdown version of this page is available at the same URL with .md appended (or via Accept: text/markdown).
Skip to main content

useWeb3Auth

Hook to access the Web3Auth context.

Import​

import { useWeb3Auth } from '@web3auth/modal/react'

Usage​

import { useWeb3Auth } from '@web3auth/modal/react'

function App() {
const { web3Auth, isConnected, isInitializing, connection, status, initError } = useWeb3Auth()

if (isConnected) {
console.log('Connected via:', connection?.connectorName)
}
if (isInitializing) {
console.log('Web3Auth is initializing')
}
if (connection?.ethereumProvider) {
// Use for JSON-RPC edge cases; prefer Wagmi hooks for standard EVM flows
console.log('Ethereum provider available')
}
if (status) {
console.log('Web3Auth status:', status)
}
if (initError) {
console.log('Web3Auth initialization error:', initError)
}
}
info

For EVM wallet operations, use Wagmi hooks (useConnection, useBalance, useSendTransaction) after setting up WagmiProvider. Use connection.ethereumProvider only for JSON-RPC methods Wagmi does not cover. See the Web SDK v11 migration guide.

Return type​

import { type IWeb3AuthContext } from '@web3auth/modal/react'

chainId​

string | null

Chain ID of the currently active chain.

chainNamespace​

ChainNamespaceType | null

Chain namespace of the currently active chain (for example, eip155 or solana).

connection​

Connection | null

Active wallet connection after sign-in, with the fields ethereumProvider, solanaWallet, connectorName, and connectorNamespace. ethereumProvider is an EIP-1193 provider for EVM; solanaWallet is a wallet-standard Solana wallet.

initError​

unknown

Error that occurred during Web3Auth initialization.

isAuthorized​

boolean

Whether the connection status is authorized (CONNECTOR_STATUS.AUTHORIZED).

isConnected​

boolean

Whether the user is connected to Web3Auth.

isInitialized​

boolean

Whether Web3Auth has completed initialization.

isInitializing​

boolean

Whether Web3Auth is currently initializing.

isMFAEnabled​

boolean

Whether Multi-Factor Authentication (MFA) is enabled for the user.

status​

CONNECTOR_STATUS_TYPE | null

Current status of the Web3Auth connection.

web3Auth​

Web3Auth | null

The Web3Auth instance.

getPlugin​

(pluginName: string) => IPlugin | null

Helper function to get a plugin by name.

setIsMFAEnabled​

(isMFAEnabled: boolean) => void

Updates the isMFAEnabled state in the context.