useBalance
Hook for getting balance of kernel account
Import
import { useBalance } from '@zerodev/waas'
Usage
import { useBalance } from '@zerodev/waas';
function App() {
const { data } = useBalance();
}
Parameters
import { type UseBalanceParameters } from '@zerodev/waas';
address
Address | undefined
The address of owner, kernel account if not specified.
tokenAddress
Address | undefined
The address of token contract, native token if not specified.
Return Types
import { type UseBalanceReturnType } from '@zerodev/waas'
data
GetBalanceReturnType | undefined
-
value
BigInt
The amount of token owned. -
decimals
number
The decimals of the token. -
symbol
string
The symbol of the token. -
formatted
string
The formatted string.
error
Error | null
- The error object for the query, if an error was thrown.
- Defaults to
null
isError / isPending / isSuccess
boolean
Boolean variables derived from status
.
isFetched
boolean
Will be true
if the query has been fetched.
isLoading
boolean
- Is
true
whenever the first fetch for a query is in-flight - Is the same as
isFetching && isPending
status
'error' | 'pending' | 'success'
pending
if there's no cached data and no query attempt was finished yet.error
if the query attempt resulted in an error. The correspondingerror
property has the error received from the attempted fetchsuccess
if the query has received a response with no errors and is ready to display its data. The correspondingdata
property on the query is the data received from the successful fetch or if the query'senabled
property is set tofalse
and has not been fetched yetdata
is the firstinitialData
supplied to the query on initialization.
refetch
(options: { cancelRefetch?: boolean | undefined; throwOnError?: boolean | undefined }) => Promise<UseQueryResult>
- A function to manually refetch the query.
throwOnError
- When set to
true
, an error will be thrown if the query fails. - When set to
false
, an error will be logged if the query fails.
- When set to
cancelRefetch
- When set to
true
, a currently running request will be cancelled before a new request is made. - When set to
false
, no refetch will be made if there is already a request running. - Defaults to
true
- When set to