React Hooks for Ethereum
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Go to file
github-actions[bot] ab40443642
chore: version packages (#2041)
15 hours ago
.changeset chore: version packages (#2041) 15 hours ago
.github chore: remove canary workflow 21 hours ago
.vscode chore: bump dev dependencies (#1405) 4 months ago
docs refactor: remove `shimChainChangedDisconnect` (#2043) 17 hours ago
examples feat: WalletConnect v2 updates (#1902) 2 weeks ago
packages chore: version packages (#2041) 15 hours ago
references@eac0650df0 chore: update references (#2044) 17 hours ago
scripts refactor: use viem utils in cli (#1992) 1 week ago
.eslintrc feat: @wagmi/cli (#1732) 2 months ago
.gitignore feat: @wagmi/cli (#1732) 2 months ago
.gitmodules feat: migrate to `@wagmi/connectors` (#1431) 3 months ago
.npmrc feat: @wagmi/cli (#1732) 2 months ago
.prettierignore Translation kick off: Simplified Chinese (#1551) 2 months ago
.prettierrc Updating wagmi to use react-query v14.4+ (#1260) 4 months ago
LICENSE chore: update license 5 days ago
README.md chore: add sponsor 4 weeks ago
package.json fix(cli): generated chain key type (#1736) 2 months ago
pnpm-lock.yaml fix: cli actions override (#2039) 22 hours ago
pnpm-workspace.yaml refactor(cli): tests (#1754) 2 months ago
tsconfig.json feat: @wagmi/cli (#1732) 2 months ago
vitest.config.ts feat: @wagmi/cli (#1732) 2 months ago

README.md

wagmi logo

React Hooks for Ethereum


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 ethers peer dependency.

npm install wagmi ethers@^5

Quick Start

Connect a wallet in under 60 seconds. LFG.

import { WagmiConfig, createClient } from 'wagmi'
import { getDefaultProvider } from 'ethers'

const client = createClient({
  autoConnect: true,
  provider: getDefaultProvider(),
})

function App() {
  return (
    <WagmiConfig client={client}>
      <Profile />
    </WagmiConfig>
  )
}
import { useAccount, useConnect, useDisconnect } from 'wagmi'
import { InjectedConnector } from 'wagmi/connectors/injected'

function Profile() {
  const { address } = useAccount()
  const { connect } = useConnect({
    connector: new InjectedConnector(),
  })
  const { disconnect } = useDisconnect()

  if (address)
    return (
      <div>
        Connected to {address}
        <button onClick={() => disconnect()}>Disconnect</button>
      </div>
    )
  return <button onClick={() => connect()}>Connect Wallet</button>
}

In this example, we create a wagmi Client and pass it to the WagmiConfig React Context. The client is set up to use the ethers Default Provider 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 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:

Support

If you find wagmi useful, please consider supporting development. Thank you πŸ™

Sponsors

paradigm logo
family logo context logo WalletConnect logo LooksRare logo PartyDAO logo Dynamic logo Sushi logo Stripe logo

Contributing

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

Authors

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

License

MIT License


Powered by Vercel