• Core
  • Getting Started

Getting Started

Installation

Install @wagmi/core and its ethers peer dependency.

npm i @wagmi/core ethers

Configure chains

First, configure your desired chains to be used by wagmi, and the providers you want to use.

import { configureChains, mainnet } from '@wagmi/core'
import { publicProvider } from '@wagmi/core/providers/public'
 
const { chains, provider, webSocketProvider } = configureChains(
  [mainnet],
  [publicProvider()],
)

This example uses the Ethereum Mainnet chain (mainnet) from @wagmi/core, however, you can also pass in any EVM-compatible chain.

Note: In a production app, it is not recommended to only pass publicProvider to configureChains as you will probably face rate-limiting on the public provider endpoints. It is recommended to also pass an alchemyProvider or infuraProvider as well.

Read more about configuring chains

Create a wagmi client

Next, create a wagmi Client instance using createClient, and pass the result from configureChains to it.

import {
  WagmiConfig,
  createClient,
  configureChains,
  mainnet,
} from '@wagmi/core'
import { publicProvider } from '@wagmi/core/providers/public'
 
const { chains, provider, webSocketProvider } = configureChains(
  [mainnet],
  [publicProvider()],
)
 
const client = createClient({
  autoConnect: true,
  provider,
  webSocketProvider,
})

Read more about client configuration

You're good to go!

Use actions! You can now import and use actions throughout your app.

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

Want to learn more? Continue on reading the documentation.