useAccountCoins
Hook for fetching fungible asset balances (coins) for a specific account, with support for pagination. If no address is provided, it defaults to the connected account.
Usage
import { useAccountCoins } from "@aptos-labs/react";
import { AccountAddress } from "@aptos-labs/ts-sdk";
export default function App() {
const { data, isLoading } = useAccountCoins({
address: AccountAddress.from(
"0x926ff619e85bdb5b02680f27bea5ea3302c71f86be4b16fa0d63df213add927a",
),
});
if (isLoading) return <div>Loading...</div>;
return (
<div>
<h1>Account Coins</h1>
<ul>
{data?.pages[0].balances.map((assetBalance) => (
<li key={assetBalance.assetType}>
{assetBalance.metadata.name} ({assetBalance.metadata.symbol}):{" "}
{assetBalance.amount}
</li>
))}
</ul>
</div>
);
}Parameters
Return Type
| Name | Type | Default |
|---|---|---|
data | InfiniteData<FetchAccountCoinsResult, unknown> | undefinedThe last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. | |
error | Error | nullThe error object for the query, if an error was thrown.
| |
isError | booleanA derived boolean from the
| |
isPending | booleanWill be | |
isLoading | booleanIs
| |
isLoadingError | booleanWill be | |
isRefetchError | booleanWill be | |
isSuccess | booleanA derived boolean from the
| |
isPlaceholderData | booleanWill be | |
status | "error" | "success" | "pending"The status of the query.
| |
fetchNextPage | (options?: FetchNextPageOptions | undefined) => Promise<InfiniteQueryObserverResult<InfiniteData<FetchAccountCoinsResult, unknown>, Error>>This function allows you to fetch the next “page” of results. | |
fetchPreviousPage | (options?: FetchPreviousPageOptions | undefined) => Promise<InfiniteQueryObserverResult<InfiniteData<FetchAccountCoinsResult, unknown>, Error>>This function allows you to fetch the previous “page” of results. | |
hasNextPage | booleanWill be | |
hasPreviousPage | booleanWill be | |
isFetchNextPageError | booleanWill be | |
isFetchingNextPage | booleanWill be | |
isFetchPreviousPageError | booleanWill be | |
isFetchingPreviousPage | booleanWill be | |
dataUpdatedAt | numberThe timestamp for when the query most recently returned the | |
errorUpdatedAt | numberThe timestamp for when the query most recently returned the | |
failureCount | numberThe failure count for the query.
| |
failureReason | Error | nullThe failure reason for the query retry.
| |
errorUpdateCount | numberThe sum of all errors. | |
isFetched | booleanWill be | |
isFetchedAfterMount | booleanWill be
| |
isFetching | booleanA derived boolean from the
| |
isInitialLoading | boolean | |
isPaused | booleanA derived boolean from the
| |
isRefetching | booleanIs
| |
isStale | booleanWill be | |
refetch | (options?: RefetchOptions | undefined) => Promise<QueryObserverResult<InfiniteData<FetchAccountCoinsResult, unknown>, Error>>A function to manually refetch the query. | |
fetchStatus | FetchStatusThe fetch status of the query.
| |
promise | Promise<InfiniteData<FetchAccountCoinsResult, unknown>>A stable promise that will be resolved with the data of the query.
Requires the |