Getting Started ​
Overview ​
Wagmi Core is a VanillaJS library for Ethereum. You can learn more about the rationale behind the project in the Why Wagmi section.
Manual Installation ​
To manually add Wagmi to your project, install the required packages.
bash
pnpm add @wagmi/core@rc @wagmi/connectors@rc viem@2.0.0-rc.0
pnpm add @wagmi/core@rc @wagmi/connectors@rc viem@2.0.0-rc.0
bash
npm install @wagmi/core@rc @wagmi/connectors@rc viem@2.0.0-rc.0
npm install @wagmi/core@rc @wagmi/connectors@rc viem@2.0.0-rc.0
bash
yarn add @wagmi/core@rc @wagmi/connectors@rc viem@2.0.0-rc.0
yarn add @wagmi/core@rc @wagmi/connectors@rc viem@2.0.0-rc.0
bash
bun add @wagmi/core@rc @wagmi/connectors@rc viem@2.0.0-rc.0
bun add @wagmi/core@rc @wagmi/connectors@rc viem@2.0.0-rc.0
- Wagmi Connectors is a collection of interfaces for linking accounts/wallets to Wagmi.
- Viem is a TypeScript interface for Ethereum that performs blockchain operations.
- TypeScript is optional, but highly recommended. Learn more about TypeScript support.
Create Config ​
Create and export a new Wagmi config using createConfig
.
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
In this example, Wagmi is configured to use the Mainnet and Sepolia chains. Check out the createConfig
docs for more configuration options.
Use Wagmi ​
Now that everything is set up, you can pass the config
to use actions.
tsx
import { getAccount, getEnsName } from '@wagmi/core'
import { config } from './config'
const { address } = getAccount(config)
const ensName = await getEnsName(config, { address })
import { getAccount, getEnsName } from '@wagmi/core'
import { config } from './config'
const { address } = getAccount(config)
const ensName = await getEnsName(config, { address })
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Next Steps ​
For more information on what to do next, check out the following topics.
- TypeScript Learn how to get the most out of Wagmi's type-safety and inference for an enlightened developer experience.
- Actions Browse the collection of actions and learn how to use them.
- Viem docs Wagmi Core is a wrapper around Viem that manages account and client reactivity. Learn more about Viem and how to use it.