import type { MultichainOptions } from '@metamask/connect-multichain'; import { EIP1193Provider } from './provider'; import type { AddEthereumChainParameter, Address, EventHandlers, Hex, MetamaskConnectEVMOptions } from './types'; /** The options for the connect method */ type ConnectOptions = { /** The account to connect to */ account?: string | undefined; /** Whether to force a request regardless of an existing session */ forceRequest?: boolean; /** All available chain IDs in the dapp in hex format */ chainIds?: Hex[]; }; export type ConnectEvmStatus = 'disconnected' | 'connected' | 'connecting'; /** * The MetamaskConnectEVM class provides an EIP-1193 compatible interface for connecting * to MetaMask and interacting with Ethereum Virtual Machine (EVM) networks. * * This class serves as a modern replacement for MetaMask SDK V1, offering enhanced * functionality and cross-platform compatibility. It wraps the Multichain SDK to provide * a simplified, EIP-1193 compliant API for dapp developers. * * Key features: * - EIP-1193 provider interface for seamless integration with existing dapp code * - Automatic session recovery when reloading or opening in new tabs * - Chain switching with automatic chain addition if not configured * - Event-driven architecture with support for connect, disconnect, accountsChanged, and chainChanged events * - Cross-platform support for browser extensions and mobile applications * - Built-in handling of common Ethereum methods (eth_accounts, wallet_switchEthereumChain, etc.) * * @example * ```typescript * const client = await createEVMClient({ * dapp: { name: 'My DApp', url: 'https://mydapp.com' } * }); * * const { accounts, chainId } = await client.connect({ chainIds: [1, 137] }); // Connect to Ethereum Mainnet, and Polygon * * const provider = client.getProvider(); * const signedMessage = await provider.request({ method: 'personal_sign', params: ['0x0', accounts[0]] }); * ``` */ export declare class MetamaskConnectEVM { #private; /** * Creates a new MetamaskConnectEVM instance. * Use the static `create()` method instead to ensure proper async initialization. * * @param options - The options for the MetamaskConnectEVM instance * @param options.core - The core instance of the Multichain SDK * @param options.eventHandlers - Optional event handlers for EIP-1193 provider events */ private constructor(); /** * Creates a fully initialized MetamaskConnectEVM instance. * This is the recommended way to instantiate the class, as it ensures * all async initialization (like session recovery) completes before * the instance is returned. * * @param options - The options for the MetamaskConnectEVM instance * @param options.core - The core instance of the Multichain SDK * @param options.eventHandlers - Optional event handlers for EIP-1193 provider events * @returns A promise that resolves with a fully initialized MetamaskConnectEVM instance */ static create(options: MetamaskConnectEVMOptions): Promise; /** * Connects to the wallet with the specified chain ID and optional account. * * @param options - The connection options * @param [options.account] - Optional param to specify an account to connect to * @param [options.forceRequest] - Optional param to force a connection request regardless of whether there is a pre-existing session * @param [options.chainIds] - Array of chain IDs to request permission for (defaults to ethereum mainnet). The first entry is used as the active chain returned by the call. Ethereum mainnet is always included in the permission request as a bootstrap fallback. * @returns A promise that resolves with the connected accounts and chain ID */ connect({ account, forceRequest, chainIds, }?: ConnectOptions): Promise<{ accounts: Address[]; chainId: Hex; }>; /** * Connects to the wallet and signs a message using personal_sign. * * @param options - The connection options * @param options.message - The message to sign after connecting * @param [options.chainIds] - Optional hex chain IDs to connect to (defaults to ethereum mainnet if not provided) * @returns A promise that resolves with the connected accounts, chainId, and signature * @throws Error if the selected account is not available after timeout */ connectAndSign({ message, chainIds, }: { message: string; chainIds?: Hex[]; }): Promise<{ accounts: Address[]; chainId: Hex; signature: string; }>; /** * Connects to the wallet and invokes a method with specified parameters. * * @param options - The options for connecting and invoking the method * @param options.method - The method name to invoke * @param options.params - The parameters to pass to the method, or a function that receives the account and returns params * @param [options.chainIds] - Optional hex chain IDs to connect to (defaults to ethereum mainnet if not provided) * @param [options.account] - Optional specific account to connect to * @param [options.forceRequest] - Whether to force a request regardless of an existing session * @returns A promise that resolves with the connected accounts, chainId, and the result of the method invocation * @throws Error if the selected account is not available after timeout (for methods that require an account) */ connectWith({ method, params, chainIds, account, forceRequest, }: { method: string; params: unknown[] | ((account: Address) => unknown[]); chainIds?: Hex[]; account?: string | undefined; forceRequest?: boolean; }): Promise<{ accounts: Address[]; chainId: Hex; result: unknown; }>; /** * Disconnects from the wallet by revoking the session and cleaning up event listeners. * * @returns A promise that resolves when disconnection is complete */ disconnect(): Promise; /** * Switches the Ethereum chain. Will track state internally whenever possible. * * @param options - The options for the switch chain request * @param options.chainId - The chain ID to switch to * @param [options.chainConfiguration] - The chain configuration to use in case the chain is not present by the wallet * @returns A promise that resolves when the chain has been switched */ switchChain({ chainId, chainConfiguration, }: { chainId: Hex; chainConfiguration?: AddEthereumChainParameter; }): Promise; /** * Gets the EIP-1193 provider instance * * @returns The EIP-1193 provider instance */ getProvider(): EIP1193Provider; /** * Announces the EIP-1193 provider through EIP-6963 wallet discovery. * * This is a no-op when a native MetaMask EIP-6963 provider has already * announced, or when running outside a browser environment. The first call * may take up to 300 ms while native providers are requested. */ announceProvider(): Promise; /** * Gets the currently selected chain ID on the wallet * * @returns The currently selected chain ID or undefined if no chain is selected */ getChainId(): Hex | undefined; /** * Gets the currently selected account on the wallet * * @returns The currently selected account or undefined if no account is selected */ getAccount(): Address | undefined; /** * Gets the currently permitted accounts * * @returns The currently permitted accounts */ get accounts(): Address[]; /** * Gets the currently selected account on the wallet * * @returns The currently selected account or undefined if no account is selected */ get selectedAccount(): Address | undefined; /** * Gets the currently selected chain ID on the wallet * * @returns The currently selected chain ID or undefined if no chain is selected */ get selectedChainId(): Hex | undefined; /** * Gets the current connection status * * @returns The current connection status */ get status(): ConnectEvmStatus; } /** * Creates a new Metamask Connect/EVM instance * * @param options - The options for the Metamask Connect/EVM layer * @param options.dapp - Dapp identification and branding settings * @param options.api - API configuration including read-only RPC map * @param options.api.supportedNetworks - A map of hex chain IDs to RPC URLs for read-only requests * @param [options.analytics.enabled] - Whether to enable dapp-side analytics (defaults to true) * @param [options.analytics.integrationType] - Integration type for analytics * @param [options.ui] - UI configuration options * @param [options.ui.headless] - Whether to run without UI * @param [options.ui.preferExtension] - Whether to prefer browser extension * @param [options.ui.showInstallModal] - Whether to render installation modal for desktop extension * @param [options.mobile] - Mobile configuration options * @param [options.mobile.preferredOpenLink] - Custom handler for opening deeplinks (useful for React Native, etc.) * @param [options.mobile.useDeeplink] - Whether to use native deeplinks instead of universal links * @param [options.transport] - Transport configuration (e.g., extensionId) * @param [options.transport.extensionId] - Extension ID for browser extension transport * @param [options.eventHandlers] - Event handlers for the Metamask Connect/EVM layer * @param [options.debug] - Enable debug logging * @param [options.skipAutoAnnounce] - Skip automatic EIP-6963 provider announcement * @returns The Metamask-Connect EVM client instance */ export declare function createEVMClient(options: Pick & { ui?: Omit; } & { eventHandlers?: Partial; debug?: boolean; skipAutoAnnounce?: boolean; api: { supportedNetworks: Record; }; }): Promise; export {}; //# sourceMappingURL=connect.d.ts.map