Client
The wagmi Client
is a framework agnostic (Vanilla JS) client that manages wallet connection state and configuration, such as: auto-connection, connectors, and ethers providers.
import { createClient } from 'wagmi'
Usage
import { createClient, configureChains, defaultChains } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public'
const { provider, webSocketProvider } = configureChains(defaultChains, [
publicProvider(),
])
const client = createClient({
provider,
webSocketProvider,
})
Configuration
autoConnect (optional)
Enables reconnecting to last used connector on mount. Defaults to false
.
import { createClient, configureChains, defaultChains } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public'
const { provider } = configureChains(defaultChains, [publicProvider()])
const client = createClient({
autoConnect: true,
provider,
})
connectors (optional)
Connectors used for linking accounts. Defaults to [new InjectedConnector()]
.
import { createClient, configureChains, defaultChains } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public'
import { InjectedConnector } from 'wagmi/connectors/injected'
import { WalletConnectConnector } from 'wagmi/connectors/walletConnect'
const { chains, provider } = configureChains(defaultChains, [publicProvider()])
const client = createClient({
connectors: [
new InjectedConnector({ chains }),
new WalletConnectConnector({
chains,
options: {
qrcode: true,
},
}),
],
provider,
})
provider
ethers interface for connecting to the Ethereum network.
import { createClient, configureChains, defaultChains } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public'
const { provider } = configureChains(defaultChains, [publicProvider()])
const client = createClient({
provider,
})
storage (optional)
The default strategy to persist and cache data. Defaults to window.localStorage
.
import { createClient, configureChains, defaultChains } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public'
const { provider } = configureChains(defaultChains, [publicProvider()])
const client = createClient({
provider,
storage: createStorage({ storage: window.localStorage }),
})
webSocketProvider (optional)
ethers WebSocket interface for connecting to the Ethereum network. If you provide a WebSocket provider, it will be used instead of polling in certain instances.
import { createClient, configureChains, defaultChains } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public'
const { provider, webSocketProvider } = configureChains(defaultChains, [
publicProvider(),
])
const client = createClient({
provider,
webSocketProvider,
})
Last updated on July 4, 2022