> ## Documentation Index
> Fetch the complete documentation index at: https://sequence-0fb8d9e6-codex-update-discord-invite.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# useGetTransactionHistory

> Hook for fetching and paginating through transaction history

## Import

```tsx theme={null}
import { useGetTransactionHistory } from '@0xsequence/hooks'
```

## Usage

```tsx theme={null}
import { useGetTransactionHistory } from '@0xsequence/hooks'

function TransactionList() {
  const {
    data,
    fetchNextPage,
    hasNextPage,
    isLoading,
    isFetchingNextPage
  } = useGetTransactionHistory({
    chainId: 1,
    accountAddresses: ['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:

```tsx theme={null}
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`

```tsx theme={null}
interface UseGetTransactionHistoryArgs {
  chainId: number
  accountAddresses: string[]
  contractAddress?: string
  tokenId?: string
  page?: {
    page: number
  }
}
```

| Parameter          | Type       | Description                                        |
| ------------------ | ---------- | -------------------------------------------------- |
| `chainId`          | `number`   | The chain ID to fetch transactions from            |
| `accountAddresses` | `string[]` | The addresses to fetch transaction history for     |
| `contractAddress`  | `string`   | (Optional) Filter transactions by contract address |
| `tokenId`          | `string`   | (Optional) Filter transactions by token ID         |
| `page`             | `object`   | (Optional) Pagination configuration                |

### options: `HooksOptions`

```tsx theme={null}
interface HooksOptions {
  disabled?: boolean
  retry?: boolean
}
```

| Parameter  | Type      | Description                                             |
| ---------- | --------- | ------------------------------------------------------- |
| `disabled` | `boolean` | (Optional) Disable the query from automatically running |
| `retry`    | `boolean` | (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.
