Johann01 / wagmi

React Hooks for Ethereum

Home Page:https://wagmi.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wagmi logo

React Hooks for Ethereum

Version License Downloads per month Best of JS Sponsors

Features

  • πŸš€ 20+ hooks for working with wallets, ENS, contracts, transactions, signing, etc.
  • πŸ’Ό Built-in wallet connectors for MetaMask, WalletConnect, Coinbase Wallet, and Injected
  • πŸ‘Ÿ Caching, request deduplication, and persistence
  • πŸŒ€ Auto-refresh data on wallet, block, and network changes
  • πŸ¦„ TypeScript ready
  • 🌳 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

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!

Community

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

Support

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

Contributing

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

Authors

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

License

WAGMIT License

About

React Hooks for Ethereum

https://wagmi.sh

License:MIT License


Languages

Language:TypeScript 99.7%Language:JavaScript 0.3%Language:Shell 0.0%