Skip to main content

Usage

const {
  data,
  isLoading,
  isError,
  isSuccess,
  error,
  refetch,
  fetchTransaction,
} = useGetTransaction({
  hashOrId: "0x...",
  getBearerToken: getToken,
});

Input Parameters

ParameterTypeRequiredDescription
hashOrIdstringYesTransaction hash (0x...) or internal ID
getBearerToken() => Promise<string>YesFunction returning the auth token
queryOptionsUseQueryOptionsNoReact Query options (e.g. staleTime, enabled)

Return Value

PropertyTypeDescription
dataTransaction | undefinedTransaction data
isLoadingbooleanTrue while fetching
isErrorbooleanTrue if an error occurred
isSuccessbooleanTrue if the query succeeded
errorError | nullError 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>
  );
}