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
| Name | Type |
|---|---|
mainnetProvider | undefined | TEthersProvider |
targetNetworkInfo? | TNetworkInfo |
options | TUpdateOptions<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
| Name | Type | Default value | Description |
|---|---|---|---|
tokenListUri | string | 'https://gateway.ipfs.io/ipns/tokens.uniswap.org' | |
chainId? | number | undefined | optional, you can filter by a particular chainId |
options | TUpdateOptions<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
| Name | Type | Description |
|---|---|---|
mainnetProvider | undefined | TEthersProvider | mainnet provider |
ensName | undefined | 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
| Name | Type | Description |
|---|---|---|
mainnetProvider | undefined | TEthersProvider | mainnet provider |
address | string |
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
| Name | Type |
|---|---|
GContract | extends BaseContract<GContract> & ERC20 |
Parameters
| Name | Type | Description |
|---|---|---|
contract | GContract | ERC20 token to get the balance of |
address | string | Address of wallet that holds the tokens |
options | TUpdateOptions<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
| Name | Type | Description |
|---|---|---|
signer1 | undefined | TEthersSigner | Object for first signer to compare |
signer2 | undefined | TEthersSigner | Object for second signer to compare |
options | TUpdateOptions<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
| Name | Type |
|---|---|
GAddress | extends string | string[] |
Parameters
| Name | Type | Description |
|---|---|---|
addresses | undefined | GAddress | Addresses of wallets to get balance for |
options | TUpdateOptions<any> | Options for how often and when to update |
override | TOverride | Options to override adapters and context |
Returns
THookResult<TUseBalanceResult<GAddress>>
current balance
Defined in
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
| Name | Type |
|---|---|
provider | undefined | TEthersProvider |
callback? | (blockNumber?: number) => void | (blockNumber?: number) => Promise<void> |
options | TUpdateOptions<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
| Name | Type |
|---|---|
signer | Signer | undefined |
account | string | 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
| Name | Type | Description |
|---|---|---|
localProvider | undefined | TEthersProvider | localhost provider |
Returns
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
| Name | Type |
|---|---|
GContract | extends BaseContract<GContract> |
Parameters
| Name | Type | Description |
|---|---|---|
contract | undefined | GContract | ethers.BaseContract class |
options | TUpdateOptions<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
| Name | Type | Description |
|---|---|---|
providerOrSigner | undefined | TEthersProviderOrSigner | input signer |
options | TUpdateOptions<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
| Name | Type |
|---|---|
GTypedEvent | extends TypedEvent<Result> |
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
contract | undefined | BaseContract | undefined | ethers.Contract |
eventFilter | undefined | string | EventFilter | undefined | - |
startBlock | number | undefined | |
toBlock | undefined | number | undefined | - |
options | TUpdateOptions<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
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
| Name | Type | Description |
|---|---|---|
chainId | undefined | number | - |
speed | TGasStationSpeed | |
currentNetworkInfo? | TNetworkInfo | uses gasPrice as a fallback |
options | TUpdateOptions<any> | - |
override | TOverride | - |
Returns
THookResult<undefined | number>
gas as gwei
Defined in
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
| Name | Type |
|---|---|
address | undefined | string |
options | TUpdateOptions<any> |
override | TOverride |
Returns
THookResult<number>
Defined in
useSignerAddress
▸ useSignerAddress(signer, options?): THookResult<undefined | string>
Summary
Get the address from the signer
Parameters
| Name | Type |
|---|---|
signer | undefined | TEthersSigner |
options | TUpdateOptions<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
| Name | Type |
|---|---|
signer | undefined | TEthersSigner |
options | TUpdateOptions<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
| Name | Type |
|---|---|
options | TUpdateOptions<any> |
override | TOverride |
Returns
THookResult<number>
Defined in
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
| Name | Type |
|---|---|
GContract | extends BaseContract<GContract> |
GContractFunc | extends (...args: any[]) => Promise<any> |
Parameters
| Name | Type | Description |
|---|---|---|
contract | undefined | GContract | Contract reading from |
contractFunc | undefined | GContractFunc | Contract variable or function to read |
args? | Parameters<GContractFunc> | Typed tuple argument to contract function or variable |
funcEventFilter? | EventFilter | Optional if only want contract to update on event |
options | TUpdateOptions<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
| Name | Type | Default value | Description |
|---|---|---|---|
update | () => void | () => Promise<void> | undefined | Function to call when update |
blockNumber | undefined | number | undefined | Current block number |
options | TUpdateOptions<any> | undefined | Options for how often and when to update |
allowBlockNumberUpdate | boolean | true | Boolean of if updating using this hook is allowed |
Returns
void