switchAccount
Action for switching between accounts in a StarkNet wallet.
Import
import { switchAccount } from "starkweb/core";Usage
index.ts
import { switchAccount } from "starkweb/core";
import { injected } from "starkweb/connectors";
import { config } from "./config";
const connector = injected();
await switchAccount(config, {
connector,
});Parameters
import { type SwitchAccountParameters } from "starkweb/core";connector
Connector
The connector instance to use for switching accounts.
index.ts
import { switchAccount } from "starkweb/core";
import { injected } from "starkweb/connectors";
import { config } from "./config";
const connector = injected();
await switchAccount(config, {
connector,
});Return Type
import { type SwitchAccountReturnType } from "starkweb/core";accounts
readonly [Address, ...Address[]]
Array of account addresses after switching.
chainId
Hex
The chain ID of the switched account.
Example
example.ts
import { switchAccount, getAccount } from "starkweb/core";
import { injected } from "starkweb/connectors";
import { config } from "./config";
// Get current account info
const account = getAccount(config);
// Switch account using injected connector
const connector = injected();
const result = await switchAccount(config, {
connector,
});
console.log("Switched to accounts:", result.accounts);
console.log("Chain ID:", result.chainId);Error
import { type SwitchAccountErrorType } from "starkweb/core";TanStack Query
import {
type SwitchAccountData,
type SwitchAccountVariables,
type SwitchAccountMutate,
type SwitchAccountMutateAsync,
switchAccountMutationOptions,
} from "starkweb/query";