https://wagmi.sh/cli/getting-started

The wagmi command line interface manages ABIs (from Etherscan/block explorers, Foundry/Hardhat projects, etc.), generates code (React Hooks, VanillaJS actions, etc.), and much more. It makes working with Ethereum easier by automating manual work (e.g. no more copying and pasting ABIs from Etherscan). You can also write plugins to extend the CLI further.

Integration

The@wagmi/cli module is used to automatically generate hooks and export ABI.

  • Config - /wagmi.config.ts
  • Output - /lib/blockchain.ts

Generate

Run the generate command to automatically export react hooks and ABI files.

Only required when adding new smart contracts or updating the config.

pnpm wagmi generate

Initial Configuration

import { defineConfig } from '@wagmi/cli'
import { react } from '@wagmi/cli/plugins'`
import { erc20ABI } from 'wagmi'

export default defineConfig({
  out: 'lib/blockchain.ts',
  contracts: [
    {
      name: 'erc20',
      abi: erc20ABI,
    },
  ],
  plugins: [react()],
})