dApp Kit
Wallet Hooks
useSwitchAccount

useSwitchAccount

The useSwitchAccount hook is a mutation hook for establishing a connection to a specific wallet.

import { ConnectButton, useAccounts, useSwitchAccount } from '@mysten/dapp-kit';
 
function MyComponent() {
	const { mutate: switchAccount } = useSwitchAccount();
	const accounts = useAccounts();
 
	return (
		<div style={{ padding: 20 }}>
			<ConnectButton />
			<ul>
				{accounts.map((account) => (
					<li key={account.address}>
						<button
							onClick={() => {
								switchAccount(
									{ account },
									{
										onSuccess: () => console.log(`switched to ${account.address}`),
									},
								);
							}}
						>
							Switch to {account.address}
						</button>
					</li>
				))}
			</ul>
		</div>
	);
}

Example

Arguments