• Core
  • Actions
  • connect

connect

Action for connecting to account with connectors.

import { connect } from '@wagmi/core'

Usage

import { connect } from '@wagmi/core'
import { InjectedConnector } from '@wagmi/core/connectors/injected'
 
const result = await connect({
  connector: new InjectedConnector(),
})

Return Value

{
  address: `0x${string}`
  chain: {
    id: number
    unsupported?: boolean
  }
  connector: Connector
  provider: Provider
}

Configuration

chainId (optional)

Chain ID to connect.

import { chain, connect } from '@wagmi/core'
import { InjectedConnector } from '@wagmi/core/connectors/injected'
 
const result = await connect({
  chainId: chain.optimism.id,
  connector: new InjectedConnector(),
})

connector

Connector to use for connecting wallet.

import { connect } from '@wagmi/core'
import { WalletConnectConnector } from '@wagmi/core/connectors/walletConnect'
 
const result = await connect({
  connector: new WalletConnectConnector(),
})