react hooks for web3
This package still need heavy testing.
It comes actually in an experimental version.
Only works with Metamask actually
yarn add web3-hooks
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>
</>
)}
</>
)
}
Real time accounts and networks change tracking
Real time ether balance tracking
Simplified use of contract with useContract
hook
MIT © AbsoluteVirtueXI
This hook is created using create-react-hook.