useAccountTokens
Hook for fetching token balances (NFTs) for a specific account, with support for pagination. If no address
is provided, it defaults to the connected account.
Usage
import { useAccountTokens } from "@aptos-labs/react";
import { AccountAddress } from "@aptos-labs/ts-sdk";
export default function App() {
const { data, isLoading } = useAccountTokens({
address: AccountAddress.from(
"0x926ff619e85bdb5b02680f27bea5ea3302c71f86be4b16fa0d63df213add927a",
),
});
if (isLoading) return <div>Loading...</div>;
return (
<div>
<h1>Account Tokens</h1>
<ul>
{data?.pages[0]?.tokens?.map((token) => (
<li key={`${token.tokenId}-v${token.tokenStandard}`}>
{token.name} ({token.collectionData?.name}): {token.amount} -{" "}
<a
href={token.metadataUri}
target="_blank"
rel="noopener noreferrer"
>
View URI
</a>
</li>
))}
</ul>
</div>
);
}
Parameters
Return Type
Name | Type | Default |
---|---|---|
data | InfiniteData<FetchAccountTokensResult, unknown> | undefined 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. The last successfully resolved data for the query. | |
error | Error | null The error object for the query, if an error was thrown.
| |
isError | boolean A derived boolean from the
| |
isPending | boolean Will be | |
isLoading | boolean Is
| |
isLoadingError | boolean Will be | |
isRefetchError | boolean Will be | |
isSuccess | boolean A derived boolean from the
| |
isPlaceholderData | boolean Will be | |
status | "error" | "success" | "pending" The status of the query.
| |
fetchNextPage | (options?: FetchNextPageOptions | undefined) => Promise<InfiniteQueryObserverResult<InfiniteData<FetchAccountTokensResult, unknown>, Error>> This function allows you to fetch the next “page” of results. | |
fetchPreviousPage | (options?: FetchPreviousPageOptions | undefined) => Promise<InfiniteQueryObserverResult<InfiniteData<FetchAccountTokensResult, unknown>, Error>> This function allows you to fetch the previous “page” of results. | |
hasNextPage | boolean Will be | |
hasPreviousPage | boolean Will be | |
isFetchNextPageError | boolean Will be | |
isFetchingNextPage | boolean Will be | |
isFetchPreviousPageError | boolean Will be | |
isFetchingPreviousPage | boolean Will be | |
dataUpdatedAt | number The timestamp for when the query most recently returned the | |
errorUpdatedAt | number The timestamp for when the query most recently returned the | |
failureCount | number The failure count for the query.
| |
failureReason | Error | null The failure reason for the query retry.
| |
errorUpdateCount | number The sum of all errors. | |
isFetched | boolean Will be | |
isFetchedAfterMount | boolean Will be
| |
isFetching | boolean A derived boolean from the
| |
isInitialLoading | boolean | |
isPaused | boolean A derived boolean from the
| |
isRefetching | boolean Is
| |
isStale | boolean Will be | |
refetch | (options?: RefetchOptions | undefined) => Promise<QueryObserverResult<InfiniteData<FetchAccountTokensResult, unknown>, Error>> A function to manually refetch the query. | |
fetchStatus | FetchStatus The fetch status of the query.
| |
promise | Promise<InfiniteData<FetchAccountTokensResult, unknown>> A stable promise that will be resolved with the data of the query.
Requires the |