Giter Site home page Giter Site logo

wagmi's Introduction

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, and Injected
  • ๐Ÿ‘Ÿ 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)
  • ๐ŸŒณ 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!

โ€”

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

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

wagmi's People

Contributors

tmm avatar github-actions[bot] avatar jxom avatar markdalgleish avatar dependabot[bot] avatar codingwithmanny avatar riklomas avatar margalit avatar alecananian avatar evalir avatar fseitun avatar lochie avatar peduarte avatar bpierre avatar wobsoriano avatar sammdec avatar sergei97k avatar erin-at-work avatar izayl avatar robriks avatar 0xflicker avatar pythonpete32 avatar anggxyz avatar toniocodo avatar chadyj avatar 0xcadams avatar cesargdm avatar kesar avatar oveddan avatar danizord avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.