Skip to content

Latest commit

 

History

History
91 lines (80 loc) · 2.29 KB

Hooks.md

File metadata and controls

91 lines (80 loc) · 2.29 KB

Hooks

This README documents the Hooks available through Web3 React. The implementation is in src/web3Hooks.js.

Hooks

import { ... } from 'web3-react/hooks'

useWeb3Context

Exposes the Web3Context.

useWeb3Context()
const context = useWeb3Context()

useAccountEffect

useAccountEffect(effect, depends = [])

useAccountEffect(effect, depends)
useAccountEffect(() => { ... }, [...])

useNetworkEffect

Identical to useEffect, except that it also triggers on network re-renders.

useNetworkEffect(effect, depends = [])
useNetworkEffect(() => { ... }, [...])

useNetworkName

Returns the name of a network (defaults to the current network).

useNetworkName(networkId)
const networkName = useNetworkName()

useEtherscanLink

Returns an Etherscan link (defaults to the current network).

useEtherscanLink(type, data, networkId)
const link = useEtherscanLink(...)

useAccountBalance

Fetches the ETH balance of an account (defaults to the current account).

useAccountBalance(address, {numberOfDigits = 3, format} = {})
const [ balance ] = useAccountBalance()

useERC20Balance

Fetches the ETH balance of an account (defaults to the current account).

useERC20Balance(ERC20Address, address, numberOfDigits = 3)
const [ ERC20Balance ] = useERC20Balance()

useSignPersonalManager

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)

useTransactionManager

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()