@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.

What is Wagmi ?

wagmi comprises a set of React Hooks that encompass all the essential components required for commencing Ethereum-related tasks. wagmi simplifies actions such as 'Wallet Connection,' presenting ENS and balance details, message signing, contract interactions, and numerous other functionalities. It incorporates caching, deduplication of requests, and persistent features for enhanced performance.

Features of Wagmi

 Here's how you can use it effectively with its numerous features:

  1. 20+ Hooks for Ethereum Tasks: wagmi provides a comprehensive collection of more than 20 React Hooks tailored for various Ethereum-related tasks. These hooks facilitate working with different aspects like wallets, ENS (Ethereum Name Service), contracts, transactions, signing messages, and more.

  1.  Built-in Wallet Connectors: wagmi includes pre-built connectors for popular wallet options such as MetaMask, WalletConnect, Coinbase Wallet, and Injected. These connectors streamline the process of integrating different wallets into your Ethereum-based applications.

  1. Caching, Request Deduplication, Multicall, Batching, and Persistence: wagmi integrates caching mechanisms to store frequently used data for quicker access, and it reduces redundant requests through deduplication. It supports multicall, enabling multiple requests to be bundled into one, enhancing efficiency. Batching further optimizes data retrieval. Persistence ensures data remains accessible even after app restarts.

  1. Auto-Refresh on Changes: wagmi automatically refreshes data when there are changes in the connected wallet, block information, or network. This feature ensures that the displayed information is up-to-date and accurate.

  1. TypeScript Ready: wagmi is compatible with TypeScript, allowing it to infer data types from ABIs (Application Binary Interfaces) and EIP-712 Typed Data. This improves code quality and helps prevent type-related errors.

  1. Command-Line Interface (CLI) for ABIs and Code Generation: The included CLI tool assists in managing ABIs (contract interfaces) and generates code. This simplifies the process of handling contract-related information and aids in generating code snippets.

  1. Test Suite Against Forked Ethereum Network: wagmi is tested against a forked Ethereum network, which simulates the behavior of the Ethereum blockchain. This ensures that the hooks and functionalities are thoroughly tested in an environment that closely resembles the real network.

These features collectively provide developers with a robust toolkit to create Ethereum applications with streamlined interactions, optimized performance, and compatibility with various wallet options and development tools.

How To Install and Use

Step 1:- run the following command Install @wagmi/core and its viem peer dependency.

npm i @wagmi/core viem
npm i @wagmi/core viem
yarn add @wagmi/core viem

Step 2:- Configure chains

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

This illustration employs the Ethereum Mainnet chain (mainnet) sourced from @wagmi/core. Nevertheless, you possess the flexibility to provide any EVM-compatible chain as an alternative.

Please note that relying solely on publicProvider within configureChains is discouraged for production applications, as it's likely to encounter rate-limiting on public provider endpoints. It is advisable to complement it with an alchemyProvider or infuraProvider for improved performance and reliability.

Step 3:- Create a wagmi config

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,
})

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

Step 4:- You are all set !

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 })

Follow these examples and videos to learn more 

We have listed some of the most important examples if you are a beginner and want to learn Wagmi:

1. Official website to get started with Wagmi

2. Write contract | Wagmi 

 
 

Conclusion

In a nutshell, wagmi emerges as a versatile Ethereum development companion, offering an array of React Hooks and integrated features for streamlined tasks like wallet connections, contract interactions, and ENS displays. With pre-built wallet connectors, advanced caching, deduplication, and multicall capabilities, wagmi optimizes performance. Its adaptability to various chains, TypeScript compatibility, and CLI tool make it a comprehensive solution. By ensuring data accuracy through auto-refresh and rigorous testing, wagmi empowers developers to craft efficient and reliable Ethereum applications.

Frequently Asked Questions

Q1. What is wagmi and what does it do?

Answer:wagmi is a library containing tools to work with Ethereum. It makes Ethereum-related tasks like connecting wallets, displaying balance and ENS information, interacting with contracts, and more, easier. It offers React Hooks that streamline these actions and enhance performance with features like caching and deduplication.

Q2. How many React Hooks does wagmi provide?

Answer: wagmi offers more than 20 React Hooks for various Ethereum tasks. These hooks are designed to facilitate interactions with components such as wallets, ENS, contracts, transactions, and message signing, among others.

Q3. What wallet options are integrated into wagmi?

Answer: wagmi includes built-in connectors for popular wallets like MetaMask, WalletConnect, Coinbase Wallet, and Injected. This simplifies the process of integrating different wallets into Ethereum-based applications.

Q4.What benefits does wagmi's caching and deduplication offer?

Answer: wagmi's caching feature stores frequently used data for quicker access, and deduplication reduces redundant requests. This leads to improved efficiency and performance when interacting with Ethereum.

Q5.How does wagmi ensure data accuracy?

Answer: wagmi has an auto-refresh feature that keeps data updated when changes occur in the connected wallet, block information, or network. This ensures that the displayed information remains accurate and current.