llms.txt
@mysten/sui v2.0 and a new dApp Kit are here! Check out the migration guide
Mysten Labs SDKs
dApp Kit (Legacy)Wallet hooks

useSwitchAccount

Legacy React mutation hook to switch the active wallet account.

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

Loading...

Arguments

  • args: Arguments passed to the connect function of the wallet.

    • account: The account to switch to.
  • options: Options passed the useMutation hook from @tanstack/react-query.

On this page