Import

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

Usage

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

function TransactionList() {
  const {
    data,
    fetchNextPage,
    hasNextPage,
    isLoading,
    isFetchingNextPage
  } = useGetTransactionHistory({
    chainId: 1,
    accountAddress: '0x123...',
    // Optional filters:
    // contractAddress: '0x456...',
    // tokenId: '1'
  })

  if (isLoading) return <div>Loading...</div>

  return (
    <div>
      {data?.pages.map(page => 
        page.transactions.map(tx => (
          <div key={tx.txnHash}>
            Transaction: {tx.txnHash}
            Block: {tx.blockNumber}
            Time: {tx.timestamp}
          </div>
        ))
      )}
      
      {hasNextPage && (
        <button 
          onClick={() => fetchNextPage()}
          disabled={isFetchingNextPage}
        >
          {isFetchingNextPage ? 'Loading more...' : 'Load more'}
        </button>
      )}
    </div>
  )
}

Return Type: UseGetTransactionHistoryReturnType

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

type UseGetTransactionHistoryReturnType = UseInfiniteQueryResult<
  InfiniteData<GetTransactionHistoryReturn, unknown>,
  Error
>

Properties

data

InfiniteData<GetTransactionHistoryReturn> | undefined

The paginated transaction history data containing multiple pages. Each page includes:

transactions

Array of transaction objects with the following properties:

  • txnHash: Transaction hash
  • blockNumber: Block number where transaction was mined
  • blockHash: Hash of the block
  • chainId: Chain ID where transaction occurred
  • metaTxnID: Optional meta transaction ID
  • transfers: Optional array of transaction transfers
  • timestamp: Transaction timestamp
page

Pagination information object containing:

  • page: Next page number
  • more: Whether more results exist in the next page
  • pageSize: Number of results per page

fetchNextPage

() => Promise<unknown>

Function to load the next page of transactions.

hasNextPage

boolean

Boolean indicating if more transactions are available to load.

isLoading

boolean

Loading state for the initial data fetch.

isFetching

boolean

Loading state for any data fetch (initial or subsequent).

isFetchingNextPage

boolean

Loading state specifically for next page fetch.

error

Error | null

Any error that occurred during data fetching.

Parameters

The hook accepts two parameters:

args: UseGetTransactionHistoryArgs

interface UseGetTransactionHistoryArgs {
  chainId: number
  accountAddress: string
  contractAddress?: string
  tokenId?: string
  page?: {
    page: number
  }
}
ParameterTypeDescription
chainIdnumberThe chain ID to fetch transactions from
accountAddressstringThe address to fetch transaction history for
contractAddressstring(Optional) Filter transactions by contract address
tokenIdstring(Optional) Filter transactions by token ID
pageobject(Optional) Pagination configuration

options: HooksOptions

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

Notes

This hook provides methods to fetch transaction history with support for infinite scrolling. It can filter transactions by contract address and token ID, making it useful for both general account history and specific asset history views.

The hook uses @tanstack/react-query internally for data fetching and caching, with a stale time of 30 seconds.