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

useSwitchAccount

Hook to switch the active wallet to another account linked to the signed-in user. See multi-wallet linking for an overview.

info

Account switching requires the user to be connected with the AUTH connector (social or passwordless login).

Import​

import { useSwitchAccount } from '@web3auth/modal/account-linking/react'

Usage​

import { useWeb3AuthUser } from '@web3auth/modal/react'
import { useSwitchAccount } from '@web3auth/modal/account-linking/react'

function WalletSwitcher() {
const { userInfo } = useWeb3AuthUser()
const { switchAccount, loading, error } = useSwitchAccount()

return (
<div>
<ul>
{userInfo?.linkedAccounts?.map(account => (
<li key={account.id}>
{account.eoaAddress}
{account.active ? (
' (active)'
) : (
<button onClick={() => switchAccount(account)} disabled={loading}>
Switch
</button>
)}
</li>
))}
</ul>
{error && <div>{error.message}</div>}
</div>
)
}

Return type​

import { type IUseSwitchAccount } from '@web3auth/modal/account-linking/react'

loading​

boolean

Whether the account switch is in progress.

error​

Web3AuthError | null

Error that occurred during the account switch.

switchAccount​

(account: LinkedAccountInfo) => Promise<void>

Switches the active wallet to account. Pass an entry from userInfo.linkedAccounts (returned by useWeb3AuthUser).