Skip to main content

Module: Hooks

Commonly used ethereum hooks to turbocharge your development! Works with useEthersContext.

Hooks

useDexEthPrice

useDexEthPrice(mainnetProvider, targetNetworkInfo?, options?): THookResult<number>

Summary

Get the Exchange price of ETH/USD (extrapolated from WETH/DAI) from uniswap

✏️ Notes
  • uses useOnRepetition, does not use context

Parameters

NameType
mainnetProviderundefined | TEthersProvider
targetNetworkInfo?TNetworkInfo
optionsTUpdateOptions<any>

Returns

THookResult<number>

price in USD

Defined in

src/hooks/dapps/useDexEthPrice.ts:27


useDexTokenList

useDexTokenList(tokenListUri?, chainId?, options?): THookResult<TokenInfo[]>

Summary

Gets a tokenlist from uniswap ipfs tokenlist

✏️ Notes
  • you can also point it to another URI

Parameters

NameTypeDefault valueDescription
tokenListUristring'https://gateway.ipfs.io/ipns/tokens.uniswap.org'
chainId?numberundefinedoptional, you can filter by a particular chainId
optionsTUpdateOptions<any>undefined-

Returns

THookResult<TokenInfo[]>

(TokenInfo[]) from '@uniswap/token-lists'

Defined in

src/hooks/dapps/useDexTokenList.ts:26


useResolveEnsAddress

useResolveEnsAddress(mainnetProvider, ensName): THookResult<undefined | string>

Summary

Gets the address from an ENS name

Parameters

NameTypeDescription
mainnetProviderundefined | TEthersProvidermainnet provider
ensNameundefined | string

Returns

THookResult<undefined | string>

Defined in

src/hooks/dapps/useResolveEnsAddress.ts:19


useResolveEnsName

useResolveEnsName(mainnetProvider, address): THookResult<undefined | string>

Summary

Gets ENS name for given address

Parameters

NameTypeDescription
mainnetProviderundefined | TEthersProvidermainnet provider
addressstring

Returns

THookResult<undefined | string>

Defined in

src/hooks/dapps/useResolveEnsName.ts:45


useTokenBalance

useTokenBalance<GContract>(contract, address, options?): THookResult<BigNumber>

Summary

Get the balance of an ERC20 token in an address

✏️ Notes
  • uses the ethers.Contract object's provider to access the network

Type parameters

NameType
GContractextends BaseContract<GContract> & ERC20

Parameters

NameTypeDescription
contractGContractERC20 token to get the balance of
addressstringAddress of wallet that holds the tokens
optionsTUpdateOptions<any>Options for how often and when to update

Returns

THookResult<BigNumber>

Defined in

src/hooks/erc/useTokenBalance.ts:32


useAreSignerEqual

useAreSignerEqual(signer1, signer2, options?): THookResult<undefined | boolean>

Summary

Are the signers equal and valid

Parameters

NameTypeDescription
signer1undefined | TEthersSignerObject for first signer to compare
signer2undefined | TEthersSignerObject for second signer to compare
optionsTUpdateOptions<any>Options for how often and when to update

Returns

THookResult<undefined | boolean>

Defined in

src/hooks/useAreSignerEqual.ts:21


useBalance

useBalance<GAddress>(addresses, options?, override?): THookResult<TUseBalanceResult<GAddress>>

Summary

Gets your balance in ETH for the given address.

✏️ Notes
  • updates triggered by BlockNumberContext
  • uses the current provider provider from useEthersContext

Type parameters

NameType
GAddressextends string | string[]

Parameters

NameTypeDescription
addressesundefined | GAddressAddresses of wallets to get balance for
optionsTUpdateOptions<any>Options for how often and when to update
overrideTOverrideOptions to override adapters and context

Returns

THookResult<TUseBalanceResult<GAddress>>

current balance

Defined in

src/hooks/useBalance.ts:46


useBlockNumber

useBlockNumber(provider, callback?, options?): THookResult<number>

Summary

Get the current block number of the network. ✋🏽

Deprecated

✏️ Notes
  • ✋🏽 For app wide block number access use useBlockNumberContext instead. See BlockNumberContext for more details, you get this as part of EthersAppContext
  • uses the current provided block number

Parameters

NameType
providerundefined | TEthersProvider
callback?(blockNumber?: number) => void | (blockNumber?: number) => Promise<void>
optionsTUpdateOptions<any>

Returns

THookResult<number>

block number

Defined in

src/hooks/useBlockNumber.ts:22


TBurnerSigner

Ƭ TBurnerSigner: Object

Summary

Return type of useBurnerSigner:

✏️ Notes
  • provides signer
  • methods of interacting with burner signer
  • methods to save and loadd signer from local storage

Type declaration

NameType
signerSigner | undefined
accountstring | undefined
saveBurner() => void
loadOrGenerateBurner() => void
generateBurnerSigner() => void
getBurnerPrivateKey() => BytesLike | undefined

Defined in

src/hooks/useBurnerSigner.ts:58


useBurnerSigner

useBurnerSigner(localProvider): TBurnerSigner

Summary

A hook that creates a burner signer/address and provides ways of interacting with and updating the signer

Parameters

NameTypeDescription
localProviderundefined | TEthersProviderlocalhost provider

Returns

TBurnerSigner

IBurnerSigner

Defined in

src/hooks/useBurnerSigner.ts:89


useContractExistsAtAddress

useContractExistsAtAddress<GContract>(contract, options?): THookResult<boolean>

Summary

Checks whether a contract exists on the blockchain

✏️ Notes
  • uses the ethers.Contract object's provider to access the network
  • checks the contract address to see if the contract is deployed

Type parameters

NameType
GContractextends BaseContract<GContract>

Parameters

NameTypeDescription
contractundefined | GContractethers.BaseContract class
optionsTUpdateOptions<boolean>-

Returns

THookResult<boolean>

Defined in

src/hooks/useContractExistsAtAddress.ts:25


useEthersAdaptorFromProviderOrSigners

useEthersAdaptorFromProviderOrSigners(providerOrSigner, options?): THookResult<undefined | TEthersAdaptor>

Summary

Gets the user TEthersUser for a signer or wallet

Parameters

NameTypeDescription
providerOrSignerundefined | TEthersProviderOrSignerinput signer
optionsTUpdateOptions<any>-

Returns

THookResult<undefined | TEthersAdaptor>

Defined in

src/hooks/useEthersAdaptorFromProviderOrSigners.ts:31


useEventListener

useEventListener<GTypedEvent>(contract, eventFilter, startBlock, toBlock?, options?): THookResult<GTypedEvent[]>

Summary

Tracks the events of associated with a contract

✏️ Notes
  • updates triggered through ethers event listener
  • uses the current provider ethersProvider from useEthersContext

Type parameters

NameType
GTypedEventextends TypedEvent<Result>

Parameters

NameTypeDefault valueDescription
contractundefined | BaseContractundefinedethers.Contract
eventFilterundefined | string | EventFilterundefined-
startBlocknumberundefined
toBlockundefined | numberundefined-
optionsTUpdateOptions<GTypedEvent[]>undefined-

Returns

THookResult<GTypedEvent[]>

Defined in

src/hooks/useEventListener.ts:26


TGasStationSpeed

Ƭ TGasStationSpeed: "fast" | "fastest" | "safeLow" | "average"

Preset speeds for Eth Gas Station API

  • fast: Recommended fast(expected to be mined in < 2 minutes) gas price in x10 Gwei(divite by 10 to convert it to gwei)
  • fastest: Recommended fastest(expected to be mined in < 30 seconds) gas price in x10 Gwei(divite by 10 to convert it to gwei)
  • safeLow: Recommended safe(expected to be mined in < 30 minutes) gas price in x10 Gwei(divite by 10 to convert it to gwei)
  • average: Recommended average(expected to be mined in < 5 minutes) gas price in x10 Gwei(divite by 10 to convert it to gwei)

Defined in

src/hooks/useGasPrice.ts:28


useGasPrice

useGasPrice(chainId, speed, currentNetworkInfo?, options?, override?): THookResult<undefined | number>

Summary

Gets the gas price for the current network as gwei

  • uses EthGasStation for mainnet
  • uses ethers.estimateGas other networks
  • can use currentNetworkInfo TNetworkInfo.gasPrice gasPrice as fallback
✏️ Notes
  • if the gas price is unknown it returns undefined
  • updates triggered by BlockNumberContext
  • uses the current provider ethersProvider from useEthersContext

Parameters

NameTypeDescription
chainIdundefined | number-
speedTGasStationSpeed
currentNetworkInfo?TNetworkInfouses gasPrice as a fallback
optionsTUpdateOptions<any>-
overrideTOverride-

Returns

THookResult<undefined | number>

gas as gwei

Defined in

src/hooks/useGasPrice.ts:48


useNonce

useNonce(address, options?, override?): THookResult<number>

Summary

Get the current nonce for the address provided

✏️ Notes
  • updates triggered by BlockNumberContext
  • uses the current provider ethersProvider from useEthersContext

Parameters

NameType
addressundefined | string
optionsTUpdateOptions<any>
overrideTOverride

Returns

THookResult<number>

Defined in

src/hooks/useNonce.ts:34


useSignerAddress

useSignerAddress(signer, options?): THookResult<undefined | string>

Summary

Get the address from the signer

Parameters

NameType
signerundefined | TEthersSigner
optionsTUpdateOptions<any>

Returns

THookResult<undefined | string>

Defined in

src/hooks/useSignerAddress.ts:19


useSignerChainId

useSignerChainId(signer, options?): THookResult<undefined | number>

Summary

Get the address from the signer

Parameters

NameType
signerundefined | TEthersSigner
optionsTUpdateOptions<any>

Returns

THookResult<undefined | number>

Defined in

src/hooks/useSignerChainId.ts:20


useTimestamp

useTimestamp(options?, override?): THookResult<number>

Summary

Get the current timestamp from the latest block

✏️ Notes
  • updates triggered by BlockNumberContext
  • uses the current provider ethersProvider from useEthersContext

Parameters

NameType
optionsTUpdateOptions<any>
overrideTOverride

Returns

THookResult<number>

Defined in

src/hooks/useTimestamp.ts:31

Misc

useCheckIsMounted

useCheckIsMounted(): void

Returns

void

Defined in

src/hooks/useCheckIsMounted.ts:3


useContractReader

useContractReader<GContract, GContractFunc>(contract, contractFunc, args?, funcEventFilter?, options?): THookResult<undefined | Awaited<ReturnType<GContractFunc>>>

Summary

Enables you to call a contract function with arguments and receive the output. You can use this to easily track of contract outputs in react states

✏️ Notes
  • uses the ethers.Contract object's provider to access the network
  • formatter is a function that can change the format of the output

Type parameters

NameType
GContractextends BaseContract<GContract>
GContractFuncextends (...args: any[]) => Promise<any>

Parameters

NameTypeDescription
contractundefined | GContractContract reading from
contractFuncundefined | GContractFuncContract variable or function to read
args?Parameters<GContractFunc>Typed tuple argument to contract function or variable
funcEventFilter?EventFilterOptional if only want contract to update on event
optionsTUpdateOptions<any>Options for how often and when to update

Returns

THookResult<undefined | Awaited<ReturnType<GContractFunc>>>

Defined in

src/hooks/useContractReader.ts:27


useEthersUpdater

useEthersUpdater(update, blockNumber, options, allowBlockNumberUpdate?): void

Summary

A hook that invokes an update callback function based on update options and ethers network state (i.e. block number)

Parameters

NameTypeDefault valueDescription
update() => void | () => Promise<void>undefinedFunction to call when update
blockNumberundefined | numberundefinedCurrent block number
optionsTUpdateOptions<any>undefinedOptions for how often and when to update
allowBlockNumberUpdatebooleantrueBoolean of if updating using this hook is allowed

Returns

void

Defined in

src/hooks/useEthersUpdater.ts:15