Injected
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 '@wagmi/core'
Usage
import { InjectedConnector } from '@wagmi/core'
const connector = new InjectedConnector()
Injected wallets can set up custom name mappings in wagmi. You can see the full list and add to it here. By default, "Injected" is the name for unmapped wallets.
Configuration
chains (optional)
Chains supported by app. Defaults to defaultChains
.
import { mainnet, optimism, polygon } from '@wagmi/core/chains'
import { InjectedConnector } from '@wagmi/core'
const connector = new InjectedConnector({
chains: [mainnet, optimism, polygon],
})
Note: The above example is using chains from @wagmi/core/chains
.
options (optional)
Options for configuring the connector.
import { InjectedConnector } from '@wagmi/core'
const connector = new InjectedConnector({
options: {
shimDisconnect: true,
},
})
getProvider
Function for selecting the EIP-1193 Ethereum Provider to target. Defaults to () => typeof window !== 'undefined' ? window.ethereum : undefined
.
import { InjectedConnector } from '@wagmi/core'
const connector = new InjectedConnector({
options: {
name: 'My Injected Wallet',
getProvider: () =>
typeof window !== 'undefined' ? window.myInjectedWallet : undefined,
},
})
name
Name of connector instead of trying to detect from browser.
import { InjectedConnector } from '@wagmi/core'
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 '@wagmi/core'
const connector = new InjectedConnector({
options: {
name: (detectedName) =>
`Injected (${
typeof detectedName === 'string'
? detectedName
: detectedName.join(', ')
})`,
},
})
shimDisconnect
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 '@wagmi/core'
const connector = new InjectedConnector({
options: {
shimDisconnect: false,
},
})