/web3-hooks

react hooks for web3

Primary LanguageJavaScript

web3-hooks

react hooks for web3

NPM JavaScript Style Guide

This package still need heavy testing.

It comes actually in an experimental version.

Only works with Metamask actually

Install

yarn add web3-hooks

Usage

import React, { useContext } from 'react'

import { Web3Context } from 'web3-hooks'

const App = () => {
  const [web3State, login] = useContext(Web3Context)
  return (
    <>
      <p>Web3: {web3State.isWeb3 ? 'injected' : 'no-injected'}</p>
      <p>Network id: {web3State.chainId}</p>
      <p>Network name: {web3State.networkName}</p>
      <p>MetaMask installed: {web3State.isMetaMask ? 'yes' : 'no'}</p>
      <p>logged: {web3State.isLogged ? 'yes' : 'no'}</p>
      <p>account: {web3State.account}</p>
      <p>Balance: {web3State.balance}</p>
      {!web3State.isLogged && (
        <>
          <button onClick={login}>login</button>
        </>
      )}
    </>
  )
}

Features

Real time accounts and networks change tracking

Real time ether balance tracking

Simplified use of contract with useContract hook

License

MIT © AbsoluteVirtueXI


This hook is created using create-react-hook.