The InjectedConnector supports wallets that inject an Ethereum Provider into the browser or window. The MetaMask browser extension is the most popular example of this.
import { InjectedConnector } from 'vagmi/connectors/injected';const connector = new InjectedConnector();
Chains supported by app. Defaults to defaultChains
.
import { chain } from 'vagmi';import { InjectedConnector } from 'vagmi/connectors/injected';const connector = new InjectedConnector({ chains: [chain.mainnet, chain.optimism],});
Options for configuring the connector.
import { InjectedConnector } from 'vagmi/connectors/injected';const connector = new InjectedConnector({ options: { shimDisconnect: true, },});
Name of connector instead of trying to detect from browser.
import { InjectedConnector } from 'vagmi/connectors/injected';const connector = new InjectedConnector({ options: { name: 'Injected', },});
name
can also be set to a function, which has the detectedName
as the first parameter. detectedName
can be a list of multiple detected names if there are multiple injected wallets detected.
import { InjectedConnector } from 'vagmi/connectors/injected';const connector = new InjectedConnector({ options: { name: detectedName => `Injected (${ typeof detectedName === 'string' ? detectedName : detectedName.join(', ') })`, },});
Certain versions of MetaMask emit the "disconnect"
event when chain is changed. This flag prevents the "disconnect"
event from being emitted upon switching chains. Defaults to false
.
import { InjectedConnector } from 'vagmi/connectors/injected';const connector = new InjectedConnector({ options: { shimChainChangedDisconnect: true, },});
MetaMask and other injected providers do not support programmatic disconnect. This flag simulates the disconnect behavior by keeping track of connection status in storage. Defaults to true
.
import { InjectedConnector } from 'vagmi/connectors/injected';const connector = new InjectedConnector({ options: { shimDisconnect: false, },});