### Example .env Setup for Starknetkit Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/configuration.md Example environment file setup for storing sensitive configuration like WalletConnect project ID and RPC endpoints. ```env VITE_WALLETCONNECT_PROJECT_ID=your_project_id VITE_STARKNET_RPC_URL=https://starknet-mainnet.public.blastapi.io VITE_DAPP_NAME=MyStarkNetApp VITE_DAPP_URL=https://mydapp.com ``` -------------------------------- ### Example Usage of KeplrMobileConnector.init Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/mobile-connectors.md Shows how to use the KeplrMobileConnector.init() static method to get a connector and then use it with the connect function. ```typescript import { KeplrMobileConnector } from "starknetkit" import { connect } from "starknetkit" const connector = KeplrMobileConnector.init() const result = await connect({ connectors: [connector] }) ``` -------------------------------- ### Complete StarkNetKit Configuration Example Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/configuration.md This example demonstrates a comprehensive configuration for StarkNetKit, including multiple custom connectors and display options. It shows how to import necessary modules and set up connectors like ArgentX, Braavos, WebWalletConnector, and ControllerConnector. ```typescript import { connect, ArgentX, Braavos } from "starknetkit" import { WebWalletConnector } from "starknetkit/webwallet" import { ControllerConnector } from "starknetkit/controller" import { constants } from "starknet" const result = await connect({ // Display options dappName: "MyStarkNetApp", modalTheme: "dark", modalMode: "canAsk", storeVersion: "chrome", // Custom connectors connectors: [ new ArgentX(), new Braavos(), new WebWalletConnector({ theme: "dark" }), new ControllerConnector() ], // This is ignored when custom connectors provided argentMobileOptions: { dappName: "MyStarkNetApp", url: "https://mystarkapp.com", projectId: process.env.VITE_WALLETCONNECT_PROJECT_ID, chainId: constants.NetworkName.SN_MAIN, icons: ["https://mystarkapp.com/logo.png"] } }) ``` -------------------------------- ### Install StarknetKit Source: https://github.com/argentlabs/starknetkit/blob/develop/README.md Install starknetkit using npm or yarn. This is the first step to integrate StarknetKit into your project. ```bash # latest official release (main branch) $ npm install starknetkit # or with yarn: $ yarn add starknetkit ``` -------------------------------- ### BraavosMobileConnector init Example Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/mobile-connectors.md Example demonstrating the usage of BraavosMobileConnector.init to create a connector instance, which is then used with the starknetkit connect function. This allows for dynamic selection of the correct Braavos connector based on the environment. ```typescript import { BraavosMobileConnector } from "starknetkit" import { connect } from "starknetkit" const connector = BraavosMobileConnector.init({ inAppBrowserOptions: { name: "Braavos Mobile" } }) const result = await connect({ connectors: [connector] }) ``` -------------------------------- ### InjectedConnector Example Configuration Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/configuration.md Example of configuring an InjectedConnector with a specific wallet ID, name, and event emission setting. ```typescript import { InjectedConnector } from "starknetkit/injected" const connector = new InjectedConnector({ options: { id: "argentX", name: "My ArgentX", shouldEmit: true } }) ``` -------------------------------- ### ControllerConnector Example Configuration Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/configuration.md Example of configuring the ControllerConnector with lazy loading enabled. ```typescript import { ControllerConnector } from "starknetkit/controller" const connector = new ControllerConnector({ lazyload: true }) ``` -------------------------------- ### Check for ArgentX Wallet Injection Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/injected-connectors.md Example demonstrating how to check if the ArgentX wallet is installed and available in the browser. ```typescript import { InjectedConnector } from "starknetkit/injected" if (InjectedConnector.isWalletInjected("argentX")) { // ArgenX is installed } ``` -------------------------------- ### ControllerConnector Connect Method Example Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/controller-connector.md Initiates the connection flow with the Controller. Includes an example of how to use it with the starknetkit connect function. ```typescript import { ControllerConnector } from "starknetkit/controller" import { connect } from "starknetkit" const result = await connect({ connectors: [new ControllerConnector()] }) if (result.connector) { console.log("Connected to Cartridge Controller") console.log("Account:", result.connectorData?.account) } ``` -------------------------------- ### Using Default Connectors Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/compound-connectors.md Example demonstrating how to initiate a connection using the default connectors provided by Starknetkit. The `connect` function automatically uses `defaultConnectors()` if no specific connectors are provided. ```typescript import { defaultConnectors } from "starknetkit" import { connect } from "starknetkit" const result = await connect({ // defaultConnectors() is used automatically if connectors not provided dappName: "My dApp" }) ``` -------------------------------- ### Example Starknetkit Connection with Environment Variables Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/configuration.md Demonstrates connecting to Starknetkit using values from environment variables for dApp name, URL, and RPC configuration. ```typescript import { connect } from "starknetkit" import { constants } from "starknet" const result = await connect({ dappName: import.meta.env.VITE_DAPP_NAME, argentMobileOptions: { dappName: import.meta.env.VITE_DAPP_NAME, url: import.meta.env.VITE_DAPP_URL, projectId: import.meta.env.VITE_WALLETCONNECT_PROJECT_ID, rpcUrl: import.meta.env.VITE_STARKNET_RPC_URL, chainId: constants.NetworkName.SN_MAIN } }) ``` -------------------------------- ### Basic Wallet Connection Example Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/hooks.md A basic React component demonstrating how to use `useStarknetkitConnectModal` to connect a wallet with custom connectors. ```typescript import { useStarknetkitConnectModal } from "starknetkit" import { ArgentX, Braavos } from "starknetkit" function MyComponent() { const { starknetkitConnectModal } = useStarknetkitConnectModal({ dappName: "My dApp", connectors: [ new ArgentX(), new Braavos() ] }) const handleConnect = async () => { try { const result = await starknetkitConnectModal() if (result.connector) { console.log("Connected!") console.log("Account:", result.connectorData?.account) } } catch (error) { console.error("Connection failed:", error) } } return ( ) } ``` -------------------------------- ### Event Listener Example Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/README.md Listen for account and network changes emitted by the selected Starknet wallet connector. ```typescript const wallet = getSelectedConnectorWallet() wallet.on("accountsChanged", (accounts) => { ... }) ``` -------------------------------- ### BraavosMobileBaseConnector Usage Example Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/mobile-connectors.md Example of how to use the BraavosMobileBaseConnector. This snippet demonstrates initializing the connector and conditionally attempting to connect on mobile devices. Ensure you import necessary functions from starknetkit. ```typescript import { BraavosMobileBaseConnector } from "starknetkit" import { connect } from "starknetkit" const connector = new BraavosMobileBaseConnector() // Only use on mobile devices if (navigator.userAgent.match(/mobile/i)) { const result = await connect({ connectors: [connector] }) } ``` -------------------------------- ### ArgentMobileBaseConnector Constructor Example Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/mobile-connectors.md Example of how to instantiate the ArgentMobileBaseConnector with necessary options. Ensure you provide your dApp name, URL, and optionally a WalletConnect v2 project ID and chain ID. ```typescript import { ArgentMobileBaseConnector } from "starknetkit" import { constants } from "starknet" const connector = new ArgentMobileBaseConnector({ dappName: "My dApp", url: "https://mydapp.com", projectId: "your-walletconnect-id", chainId: constants.NetworkName.SN_MAIN, icons: ["https://mydapp.com/logo.png"], description: "My StarkNet application" }) ``` -------------------------------- ### Example Connect Function Configuration Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/configuration.md Demonstrates how to configure the connect function with various options, including dApp name, modal theme and mode, store version, and detailed Argent Mobile connector settings. ```typescript import { connect } from "starknetkit" import { constants } from "starknet" const result = await connect({ dappName: "MyStarkApp", modalTheme: "dark", modalMode: "canAsk", storeVersion: "chrome", argentMobileOptions: { dappName: "MyStarkApp", url: "https://mystarkapp.com", projectId: "your-walletconnect-project-id", chainId: constants.NetworkName.SN_MAIN, icons: ["https://mystarkapp.com/logo.png"], description: "A powerful StarkNet application" } }) ``` -------------------------------- ### Account Change Listener with useStarknetkitConnectModal Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/hooks.md Example showing how to set up an event listener for account changes using `getSelectedConnectorWallet` and `useStarknetkitConnectModal`. ```typescript import { useStarknetkitConnectModal } from "starknetkit" import { useEffect, useState } from "react" import { getSelectedConnectorWallet } from "starknetkit" function WalletListener() { const { starknetkitConnectModal } = useStarknetkitConnectModal() const [account, setAccount] = useState(null) useEffect(() => { const wallet = getSelectedConnectorWallet() if (wallet) { wallet.on("accountsChanged", (accounts) => { console.log("Account changed to:", accounts[0]) setAccount(accounts[0]) }) return () => { wallet.off("accountsChanged", null) } } }, []) const handleConnect = async () => { const result = await starknetkitConnectModal() if (result.connectorData?.account) { setAccount(result.connectorData.account) } } return (
{account &&

Account: {account}

}
) } ``` -------------------------------- ### ControllerConnector Request Method Examples Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/controller-connector.md Makes a JSON-RPC request to the Controller. Includes examples for signing a message and requesting accounts. ```typescript // Sign a message const signature = await controller.request({ type: "wallet_signMessage", params: { message: "Sign this" } }) // Request accounts const accounts = await controller.request({ type: "wallet_requestAccounts" }) ``` -------------------------------- ### Example Usage of KeplrMobileBaseConnector Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/mobile-connectors.md Demonstrates how to instantiate and use the KeplrMobileBaseConnector. It includes error handling for cases where the user needs to complete the connection in the Keplr mobile app. ```typescript import { KeplrMobileBaseConnector } from "starknetkit" import { connect } from "starknetkit" const connector = new KeplrMobileBaseConnector() try { await connect({ connectors: [connector] }) } catch (error) { if (error.message.includes("Keplr mobile app")) { console.log("Complete the connection in Keplr mobile app") } } ``` -------------------------------- ### Connect with WebWalletConnector Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/configuration.md Example of connecting to a dApp using the WebWalletConnector with specific theme and URL options. ```typescript import { WebWalletConnector } from "starknetkit/webwallet" import { connect } from "starknetkit" const result = await connect({ connectors: [ new WebWalletConnector({ theme: "dark", url: "https://web.ready.co" // or testnet endpoint }) ] }) ``` -------------------------------- ### Detect and Connect to Installed Wallets Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/injected-connectors.md Conditionally adds ArgentX and Braavos connectors if they are detected as injected. Connects if at least one wallet is found. ```typescript import { ArgentX, Braavos } from "starknetkit" import { connect } from "starknetkit" // Only offer wallets that are installed const connectors = [] if (ArgentX.isWalletInjected()) { connectors.push(new ArgentX()) } if (Braavos.isWalletInjected()) { connectors.push(new Braavos()) } if (connectors.length > 0) { const result = await connect({ connectors, modalMode: "neverAsk" }) } else { console.log("No wallets installed") } ``` -------------------------------- ### Wallet Connection with State Management Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/hooks.md Example of using `useStarknetkitConnectModal` within a React component to manage wallet connection state. ```typescript import { useStarknetkitConnectModal } from "starknetkit" import { useState } from "react" function WalletManager() { const [wallet, setWallet] = useState(null) const { starknetkitConnectModal } = useStarknetkitConnectModal() const handleConnect = async () => { try { const result = await starknetkitConnectModal() if (result.connector && result.connectorData) { setWallet({ name: result.connector.name, account: result.connectorData.account, chainId: result.connectorData.chainId, connector: result.connector }) } } catch (error) { console.error("Connection failed:", error) } } return (
{!wallet ? ( ) : (

Connected to {wallet.name}

Account: {wallet.account}

)}
) } ``` -------------------------------- ### Manual Local Storage Access for Starknetkit Wallet Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/configuration.md Provides examples for manually accessing and clearing the 'starknetLastConnectedWallet' item from localStorage. ```typescript // Get last wallet ID const lastWalletId = localStorage.getItem("starknetLastConnectedWallet") // Clear it localStorage.removeItem("starknetLastConnectedWallet") ``` -------------------------------- ### Connect with Argent Compound Connector Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/compound-connectors.md Example of how to connect to a StarkNet dApp using the Argent compound connector, configuring both extension and mobile options. ```typescript import { Argent } from "starknetkit" import { connect } from "starknetkit" import { constants } from "starknet" const result = await connect({ connectors: [ new Argent({ extension: { // Optional: customize ArgentX extension }, mobile: { dappName: "My dApp", url: "https://mydapp.com", projectId: "your-walletconnect-project-id", chainId: constants.NetworkName.SN_MAIN, icons: ["https://mydapp.com/logo.png"], description: "My StarkNet dApp" } }) ] }) if (result.connector) { console.log("Connected via Ready:", result.connector.name) } ``` -------------------------------- ### Make Transactions with Controller Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/controller-connector.md Connects to the controller and uses the obtained account to execute transactions. Requires a provider and account setup. ```typescript import { ControllerConnector } from "starknetkit/controller" import { RpcProvider } from "starknet" const controller = new ControllerConnector() await controller.connect() const provider = new RpcProvider() const account = await controller.account(provider) // Now use account to make calls/invoke transactions const result = await account.execute({ contractAddress: "0x...", entrypoint: "transfer", calldata: ["0x...", "1000"] }) ``` -------------------------------- ### Example Usage of isInArgentMobileAppBrowser Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/mobile-connectors.md Demonstrates how to use the isInArgentMobileAppBrowser function to check if the application is running inside the Ready Mobile app's in-app browser. ```typescript import { isInArgentMobileAppBrowser } from "starknetkit" if (isInArgentMobileAppBrowser()) { console.log("Running in Ready Mobile app") } else { console.log("Running in browser or other app") } ``` -------------------------------- ### Main Entry Point Imports Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/README.md Import core functions like connect, disconnect, and getSelectedConnectorWallet from the main starknetkit package. ```APIDOC ## Main Entry Point ### Description Import core functions for managing Starknet connections. ### Import Path ```typescript import { connect, disconnect, getSelectedConnectorWallet, handleWebwalletLogoutEvent } from "starknetkit" ``` ``` -------------------------------- ### ready Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/webwallet-connector.md Asynchronously checks if the wallet is already connected and has obtained necessary account permissions. ```APIDOC ## ready ```typescript async ready(): Promise ``` Checks if wallet is already connected and has account permissions. **Returns:** `Promise` — true if logged in and authorized ``` -------------------------------- ### Fordefi Constructor Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/injected-connectors.md Shows how to instantiate the Fordefi connector with optional configuration for name, icon, and event emission. ```typescript new Fordefi(options?: Omit) ``` -------------------------------- ### Main Entry Point Imports Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/README.md Import core functions for managing Starknet connections from the main entry point of the starknetkit library. ```typescript import { connect, disconnect, getSelectedConnectorWallet, handleWebwalletLogoutEvent } from "starknetkit" ``` -------------------------------- ### Instantiate and Connect with ArgentX Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/injected-connectors.md Shows how to create an ArgentX connector instance and use it to connect to the Starknet network. ```typescript import { ArgentX } from "starknetkit" const connector = new ArgentX() const result = await connect({ connectors: [connector] }) ``` -------------------------------- ### ModalWallet Type Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/types.md Represents a wallet option displayed within the connection modal, including its name, ID, icon, and installation status. ```typescript type ModalWallet = { name: string id: string icon: ConnectorIcons installed: boolean download?: string downloads?: Record subtitle?: string title?: string connector: Connector | StarknetkitConnector | StarknetkitCompoundConnector } ``` -------------------------------- ### Get Injected Wallet by ID Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/injected-connectors.md Retrieves a specific injected wallet object from the browser's window using its unique identifier. ```typescript static getInjectedWallet(id: string): StarknetWindowObject | undefined ``` -------------------------------- ### File Organization Overview Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/DOCUMENTATION-INDEX.md Illustrates the directory structure of the StarknetKit project and the location of its documentation files. ```text /output/ ├── README.md (Start here: navigation & overview) ├── DOCUMENTATION-INDEX.md (This file) ├── types.md (Type definitions) ├── errors.md (Error handling) ├── configuration.md (Configuration options) └── api-reference/ ├── main.md (connect, disconnect, etc.) ├── connectors-base.md (Base classes) ├── injected-connectors.md (Extension wallets) ├── webwallet-connector.md (Web wallet) ├── compound-connectors.md (Argent, defaultConnectors) ├── controller-connector.md (Cartridge Controller) ├── mobile-connectors.md (Mobile wallets) └── hooks.md (React useStarknetkitConnectModal) ``` -------------------------------- ### ready Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/controller-connector.md Asynchronously checks if the ControllerConnector has been initialized and is ready for use. ```APIDOC ## ready() ### Description Asynchronously checks if the Controller is already initialized and ready. ### Returns - **Promise** - A promise that resolves to true if the controller is initialized, false otherwise. ``` -------------------------------- ### Establish Wallet Connection Source: https://github.com/argentlabs/starknetkit/blob/develop/README.md Call the connect method to establish a wallet connection. By default, it supports Ready X and Braavos connectors. ```javascript const wallet = await connect() ``` -------------------------------- ### Connect with Braavos Wallet Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/injected-connectors.md Demonstrates how to instantiate the Braavos connector and connect, after checking for its injection. ```typescript import { Braavos } from "starknetkit" const connector = new Braavos() if (Braavos.isWalletInjected()) { const result = await connect({ connectors: [connector] }) } ``` -------------------------------- ### Request Error Handling for Wallet Operations Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/errors.md Handle errors during wallet requests, such as signing messages. This example specifically checks for 'UserRejectedRequestError' to manage user cancellations. ```typescript import { getSelectedConnectorWallet } from "starknetkit" import { UserRejectedRequestError } from "starknetkit" async function makeRequest() { const wallet = getSelectedConnectorWallet() if (!wallet) { console.error("Wallet not connected") return } try { const result = await wallet.request({ type: "wallet_signMessage", params: { message: "Sign this" } }) console.log("Request successful:", result) } catch (error) { if (error instanceof UserRejectedRequestError) { console.log("User rejected the request") } else { console.error("Request failed:", error) } } } ``` -------------------------------- ### Import StarknetKit Functions Source: https://github.com/argentlabs/starknetkit/blob/develop/README.md Import necessary functions like connect and disconnect from the starknetkit package. These functions are essential for wallet interactions. ```javascript import { connect, disconnect } from "starknetkit" ``` -------------------------------- ### Connect to MetaMask Wallet Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/injected-connectors.md Demonstrates how to check if MetaMask is injected and connect to it using starknetkit. ```typescript import { MetaMask } from "starknetkit" const connector = new MetaMask() if (MetaMask.isWalletInjected()) { const result = await connect({ connectors: [connector] }) } ``` -------------------------------- ### Get Selected Wallet and Request Accounts Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/main.md Retrieves the currently selected wallet and requests account access. Use this when you need to interact with the user's wallet for transactions or other requests. ```typescript import { getSelectedConnectorWallet } from "starknetkit" const wallet = getSelectedConnectorWallet() if (wallet) { // Use wallet to make requests const accounts = await wallet.request({ type: "wallet_requestAccounts" }) } else { console.log("No wallet connected") } ``` -------------------------------- ### Connect to Starknet Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/connectors-base.md Initiates a connection to Starknet and retrieves wallet information. Use this to establish a connection with a Starknet wallet. ```typescript import { connect } from "starknetkit" const result = await connect() if (result.connector && result.connector instanceof StarknetkitConnector) { const wallet = result.connector.wallet const accounts = await wallet.request({ type: "wallet_requestAccounts" }) } ``` -------------------------------- ### Connect to Starknet Wallet Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/main.md Establishes a wallet connection. Use this for a simple connection with default connectors. ```typescript import { connect } from "starknetkit" // Simple connection with default connectors const result = await connect() if (result.connector) { console.log("Connected to:", result.connector.name) console.log("Account:", result.connectorData?.account) console.log("Chain ID:", result.connectorData?.chainId) } ``` -------------------------------- ### Connect with System Theme Detection Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/configuration.md Connect to the dApp using the 'system' modal theme, which respects the user's OS dark/light mode preference. ```typescript const result = await connect({ modalTheme: "system" // Respects OS dark/light mode }) ``` -------------------------------- ### Custom Modal Options for Wallet Connection Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/hooks.md Demonstrates how to configure `useStarknetkitConnectModal` with custom options like modal theme and specific connectors. ```typescript import { useStarknetkitConnectModal } from "starknetkit" import { WebWalletConnector } from "starknetkit/webwallet" function ConnectButton() { const { starknetkitConnectModal } = useStarknetkitConnectModal({ modalMode: "alwaysAsk", modalTheme: "dark", dappName: "Premium dApp", connectors: [ new WebWalletConnector({ theme: "dark" }) ] }) const handleClick = async () => { const result = await starknetkitConnectModal() // Handle result } return } ``` -------------------------------- ### Connector Method: connect Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/connectors-base.md Initiates the wallet connection flow. Optionally accepts connection parameters like chain ID hint or a flag to show only QR code for mobile. ```typescript abstract connect(params?: ConnectArgs): Promise ``` -------------------------------- ### Connect with Custom Options Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/main.md Establishes a wallet connection with custom options, such as always showing the modal, setting the dApp name, and specifying preferred connectors. ```typescript import { connect } from "starknetkit" import { InjectedConnector } from "starknetkit/injected" const result = await connect({ modalMode: "alwaysAsk", dappName: "My StarkNet dApp", modalTheme: "dark", connectors: [ new InjectedConnector({ options: { id: "argentX" } }), new InjectedConnector({ options: { id: "braavos" } }) ] }) ``` -------------------------------- ### Keplr Constructor Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/injected-connectors.md Illustrates instantiating the Keplr connector with optional parameters for display name, icon, and event emission. ```typescript new Keplr(options?: Omit) ``` -------------------------------- ### WebWallet Connector Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/DOCUMENTATION-INDEX.md Documentation for the connector that interfaces with the Ready web wallet. ```APIDOC ## WebWallet Connector ### Description Documentation for the `WebWalletConnector` class, enabling interaction with the Ready web wallet. ### Class: `WebWalletConnector` #### Public Methods and Properties (Details on all public methods and properties are available in the referenced file.) #### `connectAndSignSession()` ##### Description Manages session establishment and signing for the web wallet. #### Event Listener Management ##### Description Provides functionality for managing event listeners related to the web wallet connection. #### Error Types ##### `WebwalletError` ##### `ConnectAndSignSessionError` #### Features - SSO authentication - Logout handling ### Further Details Refer to `api-reference/webwallet-connector.md` for complete usage examples, SSO authentication details, and error type information. ``` -------------------------------- ### React Hooks Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/DOCUMENTATION-INDEX.md Documentation for React integration using StarknetKit hooks. ```APIDOC ## React Hooks ### Description Documentation for integrating StarknetKit with React applications using provided hooks. ### `useStarknetkitConnectModal()` Hook #### Description A React hook for managing the StarknetKit connection modal and related state. #### Return Type and Parameters (Details on the hook's return type and parameters are available in the referenced file.) #### Usage Differences ##### Description Highlights the differences between using this hook and the standalone `connect()` function. #### State Management Patterns ##### Description Illustrates common patterns for managing connection state within React components. #### Account Change Listening ##### Description Provides guidance on listening for and handling account changes. #### Reconnection Patterns ##### Description Explains strategies for handling wallet reconnection scenarios. ### Further Details Refer to `api-reference/hooks.md` for multiple usage examples and in-depth explanations. ``` -------------------------------- ### WebWalletConnector Constructor Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/webwallet-connector.md Initializes a new instance of WebWalletConnector. Options can configure the wallet URL, UI theme, and SSO token for automatic login. ```typescript new WebWalletConnector(options?: WebWalletConnectorOptions) ``` -------------------------------- ### KeplrMobileConnector.init Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/mobile-connectors.md Factory for creating the appropriate Keplr connector based on the environment. It returns the Keplr connector if running in the Keplr mobile app browser, otherwise it returns KeplrMobileBaseConnector. ```APIDOC ## KeplrMobileConnector.init ### Description Factory for creating the appropriate Keplr connector based on the environment. It returns the Keplr connector if running in the Keplr mobile app browser, otherwise it returns KeplrMobileBaseConnector. ### Method Signature ```typescript static init(params?: KeplrMobileConnectorInitParams): Connector ``` ### Parameters - `params.inAppBrowserOptions` (InjectedConnectorOptions) - Optional - Options for in-app browser. ### Returns - `Connector` — The appropriate Keplr connector. ### Example ```typescript import { KeplrMobileConnector } from "starknetkit" import { connect } from "starknetkit" const connector = KeplrMobileConnector.init() const result = await connect({ connectors: [connector] }) ``` ``` -------------------------------- ### connect Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/main.md Establishes a wallet connection by displaying a modal or attempting silent connection based on configuration. It supports various options for customizing the connection behavior, theme, and available connectors. ```APIDOC ## connect ### Description Establishes a wallet connection by displaying a modal or attempting silent connection based on configuration. It supports various options for customizing the connection behavior, theme, and available connectors. ### Method `async` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **options** (ConnectOptions | ConnectOptionsWithConnectors) - Optional - Connection configuration options. - **options.modalMode** ("alwaysAsk" | "canAsk" | "neverAsk") - Optional - Connection behavior. Defaults to "canAsk". - **options.storeVersion** ("chrome" | "firefox" | "edge" | null) - Optional - Target browser extension store. Defaults to Current browser. - **options.modalTheme** ("light" | "dark" | "system") - Optional - Modal theme color. - **options.dappName** (string) - Optional - Name of dApp displayed in modal. - **options.resultType** ("connector" | "wallet") - Optional - Return type: selected wallet or connector. Defaults to "wallet". - **options.connectors** (Connector[]) - Optional - Custom list of connectors to display. Defaults to defaultConnectors(). - **options.webWalletUrl** (string) - Optional - Ready web wallet URL. Defaults to "https://web.ready.co". - **options.argentMobileOptions** (ArgentMobileConnectorOptions) - Optional - Ready Mobile connector config. ### Return Type `Promise` where ModalResult is: ```json { "connector": "StarknetkitConnector | null", "connectorData": "ConnectorData | null", "wallet": "StarknetWindowObject | null" } ``` Returns `null` values if user rejects connection. ### Throws - `Error` - If connection fails (e.g., wallet not found, user rejects connection) ### Example ```typescript import { connect } from "starknetkit" // Simple connection with default connectors const result = await connect() if (result.connector) { console.log("Connected to:", result.connector.name) console.log("Account:", result.connectorData?.account) console.log("Chain ID:", result.connectorData?.chainId) } ``` ### Example with Custom Options ```typescript import { connect } from "starknetkit" import { InjectedConnector } from "starknetkit/injected" const result = await connect({ modalMode: "alwaysAsk", dappName: "My StarkNet dApp", modalTheme: "dark", connectors: [ new InjectedConnector({ options: { id: "argentX" } }), new InjectedConnector({ options: { id: "braavos" } }) ] }) ``` ### Example with Web Wallet ```typescript import { connect } from "starknetkit" import { WebWalletConnector } from "starknetkit/webwallet" const result = await connect({ connectors: [ new WebWalletConnector({ url: "https://web.ready.co" }) ] }) ``` ### Example Reconnecting to Previous Wallet ```typescript import { connect } from "starknetkit" // Attempt to reconnect without showing modal try { const result = await connect({ modalMode: "neverAsk" }) if (result.connector) { console.log("Reconnected to:", result.connector.name) } else { console.log("No previous wallet found") } } catch (error) { console.error("Reconnection failed:", error) } ``` ``` -------------------------------- ### Connector Base Classes Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/DOCUMENTATION-INDEX.md Documentation for the foundation classes used to build wallet connectors. ```APIDOC ## Connector Base Classes ### Description Defines the fundamental building blocks and abstract classes for creating and managing wallet connectors within StarknetKit. ### Classes #### `Connector` (Abstract Class) ##### Description An abstract base class outlining the core interface for all wallet connectors. ##### Properties - `id` (string): Unique identifier for the connector. - `name` (string): Display name of the wallet. - `icon` (string): URL or path to the wallet's icon. ##### Methods - `available()`: Checks if the wallet is available in the current environment. - `ready()`: Checks if the wallet is ready for connection. - `connect()`: Initiates the connection process with the wallet. - `disconnect()`: Disconnects the wallet session. - `account()`: Retrieves the connected account address. - `chainId()`: Retrieves the current chain ID. - `request(args)`: Sends a request to the wallet. ##### Event System Supports events for `connect`, `change` (account/chain updates), and `disconnect`. #### `StarknetkitConnector` ##### Description A concrete implementation extending `Connector`, providing StarknetKit-specific wallet access. #### `StarknetkitCompoundConnector` ##### Description Facilitates the combination of multiple connectors into a single, unified interface. ### Further Details Refer to `api-reference/connectors-base.md` for complete event documentation and detailed explanations. ``` -------------------------------- ### Connect with WebWalletConnector Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/webwallet-connector.md Initiates the wallet connection process by opening the web wallet login flow. Ensure the WebWalletConnector is included in the connectors array when calling the connect function. ```typescript import { WebWalletConnector } from "starknetkit/webwallet" import { connect } from "starknetkit" const result = await connect({ connectors: [ new WebWalletConnector({ theme: "dark" }) ] }) ``` -------------------------------- ### connect Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/webwallet-connector.md Initiates the wallet connection process by opening the web wallet login flow, typically in a popup or iframe. It can optionally accept a chain ID hint. ```APIDOC ## connect ```typescript async connect(params?: ConnectArgs): Promise ``` Initiates wallet connection. Opens web wallet login flow in popup/iframe. **Parameters:** | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | params.onlyQRCode | boolean | No | (Not used for web wallet) | | params.chainIdHint | bigint | No | Hint for preferred chain | **Returns:** `Promise` — { account, chainId } **Throws:** - `UserRejectedRequestError` — User closed login flow - `ConnectorNotFoundError` — Wallet initialization failed **Example:** ```typescript import { WebWalletConnector } from "starknetkit/webwallet" import { connect } from "starknetkit" const result = await connect({ connectors: [ new WebWalletConnector({ theme: "dark" }) ] }) ``` ``` -------------------------------- ### BraavosMobileConnector Static init Method Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/mobile-connectors.md Provides a factory method to initialize the appropriate Braavos connector. It returns the Braavos connector if running within the Braavos mobile app browser, otherwise it returns the BraavosMobileBaseConnector. ```typescript export class BraavosMobileConnector { static init(params?: BraavosMobileConnectorInitParams): Connector } ``` -------------------------------- ### Connect with Light Theme Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/configuration.md Connect to the dApp forcing the modal to use the light theme, regardless of OS settings. ```typescript const result = await connect({ modalTheme: "light" // Force light theme }) ``` -------------------------------- ### ControllerConnector Ready Method Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/controller-connector.md Asynchronously checks if the Controller is already initialized and ready for use. Returns a promise that resolves to a boolean. ```typescript async ready(): Promise ``` -------------------------------- ### Connect using Web Wallet Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/main.md Establishes a wallet connection specifically using the Web Wallet connector. ```typescript import { connect } from "starknetkit" import { WebWalletConnector } from "starknetkit/webwallet" const result = await connect({ connectors: [ new WebWalletConnector({ url: "https://web.ready.co" }) ] }) ``` -------------------------------- ### WebWalletConnector Constructor Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/webwallet-connector.md Initializes a new instance of the WebWalletConnector. It allows configuration of the wallet URL, UI theme, and SSO token for automatic login. ```APIDOC ## WebWalletConnector Constructor ```typescript new WebWalletConnector(options?: WebWalletConnectorOptions) ``` ### Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | options.url | string | No | "https://web.ready.co" | Web wallet URL (for testnet, contact Ready) | | options.theme | "light" \| "dark" \| null | No | null | UI theme (null = system theme) | | options.ssoToken | string | No | — | SSO token for automatic login | | options.authorizedPartyId | string | No | — | Party ID for SSO | ``` -------------------------------- ### Initialize Account Change Event Listener Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/webwallet-connector.md Registers a callback function to be executed when account change events occur. Ensures the wallet is connected before registering. ```typescript async initEventListener(handler: AccountChangeEventHandler): Promise ``` -------------------------------- ### BraavosMobileConnector.init Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/mobile-connectors.md Factory for creating the appropriate Braavos connector based on the environment. It returns the Braavos connector if running in the Braavos mobile app browser, otherwise it returns BraavosMobileBaseConnector. ```APIDOC ## BraavosMobileConnector.init Factory for creating the appropriate Braavos connector based on environment. ### Static Method: init ```typescript BraavosMobileConnector.init(params?: BraavosMobileConnectorInitParams): Connector ``` Returns `Braavos` connector if running in Braavos mobile app browser, otherwise `BraavosMobileBaseConnector`. #### Parameters - **params.inAppBrowserOptions** (InjectedConnectorOptions) - No - Options for in-app browser #### Returns - `Connector` — Appropriate Braavos connector ### Example ```typescript import { BraavosMobileConnector } from "starknetkit" import { connect } from "starknetkit" const connector = BraavosMobileConnector.init({ inAppBrowserOptions: { name: "Braavos Mobile" } }) const result = await connect({ connectors: [connector] }) ``` ``` -------------------------------- ### Web Wallet Imports Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/README.md Import the WebWalletConnector and related utilities for handling web-based wallet connections. ```APIDOC ## Web Wallet ### Description Import the connector for web-based wallets and related event handlers. ### Import Path ```typescript import { WebWalletConnector } from "starknetkit/webwallet" import { handleWebwalletLogoutEvent, WebwalletError } from "starknetkit/webwallet" ``` ``` -------------------------------- ### Default Connectors Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/compound-connectors.md Retrieves a pre-configured list of default connectors provided by Starknetkit. ```APIDOC ## defaultConnectors() ### Description Returns an array of default connectors that can be used to connect to StarkNet. ### Returns Array of connectors that includes: 1. **ArgentX** — Ready X browser extension 2. **Braavos** — Braavos wallet (if not on Safari) 3. **MetaMask** — MetaMask extension (if injected and not on Safari) 4. **Fordefi** — Fordefi wallet (if injected and not on Safari) 5. **Keplr** — Keplr extension (if injected and not on Safari) 6. **Xverse** — Xverse wallet (if injected and not on Safari) 7. **ControllerConnector** — Cartridge Controller 8. **BraavosMobileBaseConnector** — Braavos mobile (on mobile devices) 9. **KeplrMobileBaseConnector** — Keplr mobile (on mobile devices) ### Example ```typescript import { defaultConnectors } from "starknetkit" import { connect } from "starknetkit" const result = await connect({ // defaultConnectors() is used automatically if connectors not provided dappName: "My dApp" }) ``` ``` -------------------------------- ### Connector Methods: available, ready Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/connectors-base.md Abstract methods to check if a connector is available in the current environment and if it's already authorized and ready to use. ```typescript abstract available(): boolean ``` ```typescript abstract ready(): Promise ``` -------------------------------- ### Listen for Account Changes Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/main.md Sets up a listener for 'accountsChanged' events from the selected wallet. This is useful for updating the UI when the user switches accounts within their wallet. ```typescript import { getSelectedConnectorWallet } from "starknetkit" const wallet = getSelectedConnectorWallet() if (wallet) { wallet.on("accountsChanged", () => { console.log("Account changed") // Update UI with new account }) } ``` -------------------------------- ### React Hooks Imports Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/README.md Import React hooks provided by Starknetkit for seamless integration into React applications. ```APIDOC ## React Hooks ### Description Import React hooks for managing Starknetkit functionalities within React components. ### Import Path ```typescript import { useStarknetkitConnectModal } from "starknetkit" ``` ``` -------------------------------- ### WebWalletConnectorOptions Interface Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/types.md Configuration options for the Ready web wallet connector. Supports custom URLs and themes. ```typescript interface WebWalletConnectorOptions { url?: string theme?: Theme ssoToken?: string authorizedPartyId?: string } ``` -------------------------------- ### Connector Event: connect Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/connectors-base.md Listens for the 'connect' event, emitted when a wallet connection is successfully established. Logs the connected account data. ```typescript connector.on("connect", (data: ConnectorData) => { console.log("Connected to account:", data.account) }) ``` -------------------------------- ### Default Connectors with Mobile Detection Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/mobile-connectors.md Illustrates how default connectors are obtained, noting that StarknetKit automatically includes mobile connectors like BraavosMobileBaseConnector and KeplrMobileBaseConnector when running on a mobile device. ```typescript import { defaultConnectors } from "starknetkit" const connectors = defaultConnectors() // If on mobile: includes BraavosMobileBaseConnector and KeplrMobileBaseConnector // If on desktop: only includes desktop wallets ``` -------------------------------- ### StarknetkitConnector Class Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/connectors-base.md Extends the base Connector class and provides access to the StarknetWindowObject for making wallet requests. ```APIDOC ## StarknetkitConnector Class Extends `Connector` and provides access to the StarknetWindowObject. ### Properties #### wallet ```typescript abstract get wallet(): StarknetWindowObject ``` The wallet's StarknetWindowObject for making requests. **Throws:** - `ConnectorNotConnectedError` — Wallet not connected ``` -------------------------------- ### ControllerConnector Account Method Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/controller-connector.md Returns a Starknet account interface for the connected Controller. Requires a Starknet provider as an argument and throws errors if not connected or authenticated. ```typescript async account(provider: ProviderOptions | ProviderInterface): Promise ``` -------------------------------- ### StarknetkitConnector Abstract Base Class Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/connectors-base.md Extends the base Connector class and provides access to the wallet's StarknetWindowObject. Implementations must define the 'wallet' property. ```typescript abstract class StarknetkitConnector extends Connector { abstract get wallet(): StarknetWindowObject } ``` -------------------------------- ### Web Wallet Imports Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/README.md Import the WebWalletConnector and related utilities for handling web-based wallet connections and logout events. ```typescript import { WebWalletConnector } from "starknetkit/webwallet" import { handleWebwalletLogoutEvent, WebwalletError } from "starknetkit/webwallet" ``` -------------------------------- ### Web Wallet Connection with Custom Theme Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/webwallet-connector.md Configures the WebWalletConnector with a custom theme ('light', 'dark', or null for system default) and optionally specifies a custom URL for the wallet instance. ```typescript import { WebWalletConnector } from "starknetkit/webwallet" const connector = new WebWalletConnector({ theme: "light", // or "dark" or null for system url: "https://testnet.web.ready.co" // For testnet }) const result = await connect({ connectors: [connector] }) ``` -------------------------------- ### ConnectOptions Interface Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/types.md Specifies the configuration options for the connect() function, including dApp name, modal behavior, and theme. ```typescript interface ConnectOptions extends GetWalletOptions { dappName?: string modalMode?: "alwaysAsk" | "canAsk" | "neverAsk" modalTheme?: "light" | "dark" | "system" storeVersion?: StoreVersion | null resultType?: "connector" | "wallet" webWalletUrl?: string argentMobileOptions: ArgentMobileConnectorOptions skipEmit?: boolean } ``` -------------------------------- ### Connector Method: account Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/connectors-base.md Retrieves a Starknet AccountInterface for the connected wallet. Requires a provider for account creation and throws an error if not connected. ```typescript abstract account(provider: ProviderOptions | ProviderInterface): Promise ``` -------------------------------- ### Basic Web Wallet Connection Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/webwallet-connector.md Connects to a web wallet using the WebWalletConnector. Initializes the connection with a dApp name and modal theme. ```typescript import { WebWalletConnector } from "starknetkit/webwallet" import { connect } from "starknetkit" const result = await connect({ connectors: [new WebWalletConnector()], dappName: "My dApp", modalTheme: "dark" }) if (result.connector) { console.log("Connected via web wallet") console.log("Account:", result.connectorData?.account) } ``` -------------------------------- ### Injected Connectors Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/DOCUMENTATION-INDEX.md Documentation for connectors that interact with browser extension wallets. ```APIDOC ## Injected Connectors ### Description Provides documentation for connectors that interface with browser extension-based Starknet wallets. ### Base Class #### `InjectedConnector` ##### Description Base class for all injected wallet connectors. ##### Static Methods - `getInjectedWallet()`: Detects and returns information about an injected wallet. - `isWalletInjected()`: Checks if a specific wallet is injected into the browser. ### Individual Wallet Implementations - **`ArgentX` (Ready X)** - **`Braavos`** - **`MetaMask`** - **`Fordefi`** - **`Keplr`** - **`Xverse`** Each implementation details specific configuration options and usage patterns. ### Further Details Refer to `api-reference/injected-connectors.md` for detailed configuration options, usage examples, and patterns for each individual wallet. ``` -------------------------------- ### Basic Controller Connection Source: https://github.com/argentlabs/starknetkit/blob/develop/_autodocs/api-reference/controller-connector.md Establishes a basic connection using the ControllerConnector. This is the simplest way to integrate the controller. ```typescript import { ControllerConnector } from "starknetkit/controller" import { connect } from "starknetkit" const connector = new ControllerConnector() const result = await connect({ connectors: [connector] }) if (result.connector?.id === "controller") { console.log("Connected via Cartridge Controller") } ```