Usage
const {
data,
isLoading,
isError,
isSuccess,
error,
refetch,
fetchTransaction,
} = useGetTransaction({
hashOrId: "0x...",
getBearerToken: getToken,
});
Input Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
hashOrId | string | Yes | Transaction hash (0x...) or internal ID |
getBearerToken | () => Promise<string> | Yes | Function returning the auth token |
queryOptions | UseQueryOptions | No | React Query options (e.g. staleTime, enabled) |
Return Value
| Property | Type | Description |
|---|---|---|
data | Transaction | undefined | Transaction data |
isLoading | boolean | True while fetching |
isError | boolean | True if an error occurred |
isSuccess | boolean | True if the query succeeded |
error | Error | null | Error when isError is true |
refetch | () => Promise<QueryObserverResult> | Re-run the query |
fetchTransaction | (input) => Promise<Transaction> | Imperatively fetch with custom params |
Example Implementation
import { useGetTransaction } from "@chipi-stack/chipi-react";
export function TransactionDetail({
txHash,
getBearerToken,
}: {
txHash: string;
getBearerToken: () => Promise<string>;
}) {
const { data: tx, isLoading, error } = useGetTransaction({
hashOrId: txHash,
getBearerToken,
});
if (isLoading) return <p>Loading transaction...</p>;
if (error) return <p>Error: {error.message}</p>;
return (
<div>
<p>Hash: {tx?.transactionHash}</p>
<p>Status: {tx?.status}</p>
<p>From: {tx?.senderAddress}</p>
<p>To: {tx?.destinationAddress}</p>
<p>Amount: {tx?.amount} {tx?.token}</p>
</div>
);
}
