• Core
  • Getting Started

Getting Started

@wagmi/core is a VanillaJS library containing everything you need to start working with Ethereum. It makes it easy to "Connect Wallet," display ENS and balance information, sign messages, interact with contracts, and much more. If you are wanting to use @wagmi/core with wagmi in React, please refer to the Actions section.

Installation

Install @wagmi/core and its viem peer dependency.

npm i @wagmi/core viem

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, publicClient, webSocketPublicClient } = 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 config

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

import {
  createConfig,
  configureChains,
  mainnet,
} from '@wagmi/core'
import { publicProvider } from '@wagmi/core/providers/public'
 
const { chains, publicClient, webSocketPublicClient } = configureChains(
  [mainnet],
  [publicProvider()],
)
 
const config = createConfig({
  autoConnect: true,
  publicClient,
  webSocketPublicClient,
})

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 { account } = await connect({
  connector: new InjectedConnector(),
})
const ensName = await fetchEnsName({ address: account })

Want to learn more? Continue on reading the documentation.