useTransaction
Hook for fetching a single transaction by hash or ledger version.
Usage
Transaction Hash
import { useTransaction } from "@aptos-labs/react";
export default function App() {
const { data: transaction, isLoading } = useTransaction({
transactionHash: "0x1234567890abcdef",
});
if (isLoading) return <div>Loading...</div>;
return (
<div>
<h1>Transaction</h1>
<pre>{JSON.stringify(transaction, null, 2)}</pre>
</div>
);
}Ledger Version
import { useTransaction } from "@aptos-labs/react";
export default function App() {
const { data: transaction, isLoading } = useTransaction({
ledgerVersion: 1234567890,
});
if (isLoading) return <div>Loading...</div>;
return (
<div>
<h1>Transaction</h1>
<pre>{JSON.stringify(transaction, null, 2)}</pre>
</div>
);
}Parameters
Return Type
| Name | Type | Default |
|---|---|---|
data | TransactionResponse | 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.
| |
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<TransactionResponse, Error>>A function to manually refetch the query. | |
fetchStatus | FetchStatusThe fetch status of the query.
| |
promise | Promise<TransactionResponse>A stable promise that will be resolved with the data of the query.
Requires the |