UNPKG

viem

Version:

TypeScript Interface for Ethereum

34 lines 1.5 kB
import type { Account } from '../../accounts/types.js'; import type { Client } from '../../clients/createClient.js'; import type { Transport } from '../../clients/transports/createTransport.js'; import type { ErrorType } from '../../errors/utils.js'; import type { Chain } from '../../types/chain.js'; import type { RequestErrorType } from '../../utils/buildRequest.js'; import { type NumberToHexErrorType } from '../../utils/encoding/toHex.js'; export type SwitchChainParameters = { /** ID of Chain to switch to */ id: Chain['id']; }; export type SwitchChainErrorType = NumberToHexErrorType | RequestErrorType | ErrorType; /** * Switch the target chain in a wallet. * * - Docs: https://viem.sh/docs/actions/wallet/switchChain * - JSON-RPC Methods: [`eth_switchEthereumChain`](https://eips.ethereum.org/EIPS/eip-3326) * * @param client - Client to use * @param parameters - {@link SwitchChainParameters} * * @example * import { createWalletClient, custom } from 'viem' * import { mainnet, optimism } from 'viem/chains' * import { switchChain } from 'viem/wallet' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) * await switchChain(client, { id: optimism.id }) */ export declare function switchChain<chain extends Chain | undefined, account extends Account | undefined = undefined>(client: Client<Transport, chain, account>, { id }: SwitchChainParameters): Promise<void>; //# sourceMappingURL=switchChain.d.ts.map