wagmi

React Hooks for Ethereum

README

wagmi


Features


- 🚀 20+ hooks for working with wallets, ENS, contracts, transactions, signing, etc.
- 💼 Built-in wallet connectors for MetaMask, WalletConnect, Coinbase Wallet, Injected, and more
- 👟 Caching, request deduplication, multicall, batching, and persistence
- 🌀 Auto-refresh data on wallet, block, and network changes
- 🦄 TypeScript ready (infer types from ABIs and EIP-712 Typed Data)
- 📦 Command-line interface for managing ABIs and code generation
- 🌳 Test suite running against forked Ethereum network

...and a lot more.

Documentation


For full documentation and examples, visit wagmi.sh.

Installation


Install wagmi and its viem peer dependency.

  1. ```bash
  2. npm install wagmi viem
  3. ```

Quick Start


Connect a wallet in under 60 seconds. LFG.

  1. ```tsx
  2. import { WagmiConfig, createConfig, mainnet } from 'wagmi'
  3. import { createPublicClient, http } from 'viem'

  4. const config = createConfig({
  5.   autoConnect: true,
  6.   publicClient: createPublicClient({
  7.     chain: mainnet,
  8.     transport: http(),
  9.   }),
  10. })

  11. function App() {
  12.   return (
  13.     <WagmiConfig config={config}>
  14.       <Profile />
  15.     </WagmiConfig>
  16.   )
  17. }
  18. ```

  1. ```tsx
  2. import { useAccount, useConnect, useDisconnect } from 'wagmi'
  3. import { InjectedConnector } from 'wagmi/connectors/injected'

  4. function Profile() {
  5.   const { address } = useAccount()
  6.   const { connect } = useConnect({
  7.     connector: new InjectedConnector(),
  8.   })
  9.   const { disconnect } = useDisconnect()

  10.   if (address)
  11.     return (
  12.       <div>
  13.         Connected to {address}
  14.         <button onClick={() => disconnect()}>Disconnect</button>
  15.       </div>
  16.     )
  17.   return <button onClick={() => connect()}>Connect Wallet</button>
  18. }
  19. ```

In this example, we create a wagmi config and pass it to the WagmiConfig React Context. The config is set up to use viem's Public Client and automatically connect to previously connected wallets.

Next, we use the useConnect hook to connect an injected wallet (e.g. MetaMask) to the app. Finally, we show the connected account's address with useAccount and allow them to disconnect with useDisconnect.

We've only scratched the surface for what you can do with wagmi!


Check out RainbowKit, ConnectKit or Web3Modal to get started with pre-built interface on top of wagmi for managing wallet connections.

Community


Check out the following places for more wagmi-related content:

- Follow @wevm_dev on Twitter for project updates
- Share your project/organization using wagmi
- Browse the awesome-wagmi list of awesome projects and resources

Support


If you find wagmi useful, please consider supporting development. Thank you 🙏


Contributing


If you're interested in contributing, please read the contributing doc before submitting a pull request.

Authors


- @tmm (awkweb.eth, Twitter)
- @jxom (moxey.eth, Twitter)

Thanks to julianhutton.eth (@julianjhutton) for providing the awesome logo!