Import

import { useGetTransactionHistorySummary } from '@0xsequence/hooks'

Usage

import { useGetTransactionHistorySummary } from '@0xsequence/hooks'
import { useAccount } from 'wagmi'

function TransactionHistory() {
  const { address } = useAccount()
  
  const {
    data: transactions,
    isLoading,
    isError,
    error
  } = useGetTransactionHistorySummary({
    accountAddress: address || '',
    chainIds: [1, 137] // Fetch from Ethereum and Polygon
  })

  if (isLoading) return <div>Loading...</div>
  if (isError) return <div>Error: {error.message}</div>

  return (
    <div>
      {transactions?.map(tx => (
        <div key={tx.txnHash}>
          <h3>Transaction: {tx.txnHash}</h3>
          <p>Chain: {tx.chainId}</p>
          <p>Time: {new Date(tx.timestamp).toLocaleString()}</p>
          {tx.transfers?.map((transfer, index) => (
            <div key={index}>
              <p>From: {transfer.from}</p>
              <p>To: {transfer.to}</p>
              <p>Value: {transfer.value}</p>
            </div>
          ))}
        </div>
      ))}
    </div>
  )
}

Return Type: UseQueryResult<Transaction[]>

The hook returns all properties from React Query’s UseQueryResult with transaction data. Here’s the detailed structure:

interface TxnTransfer {
    transferType: TxnTransferType;
    contractAddress: string;
    contractType: ContractType;
    from: string;
    to: string;
    tokenIds?: Array<string>;
    amounts: Array<string>;
    logIndex: number;
    contractInfo?: ContractInfo;
    tokenMetadata?: {
        [key: string]: TokenMetadata;
    };
}

interface Transaction {
  txnHash: string
  chainId: number
  timestamp: string
  blockNumber: number
  blockHash: string
  metaTxnID?: string
  transfers?: Array<TxnTransfer>
}

Properties

data

Transaction[] | undefined

Array of transactions from all specified chains, sorted by timestamp (newest first). Each transaction includes:

  • txnHash: Transaction hash
  • chainId: Chain ID where transaction occurred
  • timestamp: Transaction timestamp
  • blockNumber: Block number where transaction was mined
  • blockHash: Hash of the block
  • metaTxnID: Optional meta transaction ID
  • transfers: Array of transfer objects with normalized addresses

isLoading

boolean

Loading state for the initial data fetch.

isError

boolean

Error state indicating if the query failed.

error

Error | null

Any error that occurred during data fetching.

Parameters

The hook accepts two parameters:

args: GetTransactionHistorySummaryArgs

interface GetTransactionHistorySummaryArgs {
  accountAddress: string
  chainIds: number[]
}
ParameterTypeDescription
accountAddressstringThe account address to fetch transactions for
chainIdsnumber[]Array of chain IDs to fetch transactions from

options: HooksOptions

interface HooksOptions {
  disabled?: boolean
  retry?: boolean
}
ParameterTypeDescription
disabledboolean(Optional) Disable the query from automatically running
retryboolean(Optional) Whether to retry failed queries