This README documents the Hooks available through Web3 React. The implementation is in src/web3Hooks.js.
import { ... } from 'web3-react/hooks'
Exposes the Web3Context
.
useWeb3Context()
const context = useWeb3Context()
useAccountEffect(effect, depends = [])
useAccountEffect(effect, depends)
useAccountEffect(() => { ... }, [...])
Identical to useEffect
, except that it also triggers on network re-renders.
useNetworkEffect(effect, depends = [])
useNetworkEffect(() => { ... }, [...])
Returns the name of a network (defaults to the current network).
useNetworkName(networkId)
const networkName = useNetworkName()
Returns an Etherscan link (defaults to the current network).
useEtherscanLink(type, data, networkId)
const link = useEtherscanLink(...)
Fetches the ETH balance of an account (defaults to the current account).
useAccountBalance(address, {numberOfDigits = 3, format} = {})
const [ balance ] = useAccountBalance()
Fetches the ETH balance of an account (defaults to the current account).
useERC20Balance(ERC20Address, address, numberOfDigits = 3)
const [ ERC20Balance ] = useERC20Balance()
Wraps the signPersonal
utility function with current Web3Context
values.
useSignPersonal(message, { handlers = {} })
handlers
must be one of: ['success', 'error']
.
const [signatureState, signatureData, signPersonal, resetSignature] = useSignPersonalManager(message)
Wraps the sendTransaction
utility function with current Web3Context
values.
useSendTransaction(method, { handlers = {}, transactionOptions = {}, maximumConfirmations = null } = {})
handlers
must be one of: ['transactionHash', 'receipt', 'confirmation', 'error']
.
const [ sendTransaction, transactionErrors ] = useSendTransaction()