• 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 { connect } from '@wagmi/core'
import { optimism } from '@wagmi/core/chains'
import { InjectedConnector } from '@wagmi/core/connectors/injected'
 
const result = await connect({
  chainId: optimism.id,
  connector: new InjectedConnector(),
})

Note: The above example is using the optimism chain from @wagmi/core/chains.

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(),
})