connect
Action for connecting to a StarkNet wallet.
Import
import { connect } from "starkweb/core"
Usage
index.ts
import { connect } from "starkweb/core"
import { injected } from "starkweb/connectors"
import { config } from "./config"
const result = await connect(config, {
connector: injected()
})
Parameters
import { type ConnectParameters } from "starkweb/core"
connector
Connector | CreateConnectorFn
The connector instance or connector creator function to use for connecting.
index.ts
import { connect } from "starkweb/core"
import { injected } from "starkweb/connectors"
const result = await connect(config, {
connector: injected()
})
chainId (optional)
Hex | undefined
The chain ID to connect to. If not provided, will use the connector's default chain.
index.ts
import { connect } from "starkweb/core"
import { mainnet } from "starkweb/chains"
const result = await connect(config, {
connector: injected(),
chainId: mainnet.chain_id
})
Return Type
import { type ConnectReturnType } from "starkweb/core"
accounts
readonly [Address, ...Address[]]
Array of account addresses that were connected.
chainId
Hex
The chain ID that was connected to.
Example
example.ts
import { connect } from "starkweb/core"
import { injected } from "starkweb/connectors"
import { config } from "./config"
// Connect using injected connector
const result = await connect(config, {
connector: injected(),
chainId: mainnet.chain_id
})
// Access connected accounts
const [account] = result.accounts
console.log('Connected to:', account)
// Check connected chain
const chainId = result.chainId
Error
import { type ConnectErrorType } from "starkweb/core"
TanStack Query
import {
type ConnectData,
type ConnectVariables,
type ConnectMutate,
type ConnectMutateAsync,
connectMutationOptions,
} from "starkweb/query"