Skip to main content
Trails comes with a built in high-performant indexer which you can leverage seamlessly to retrieve information about a user’s transaction history.

Wallet Transaction History

Query a user’s transaction history for a specific chain using their connected wallet address:
import { useAccountTransactionHistory } from '0xtrails'
import { useAccount } from 'wagmi'

export const TransactionList = () => {
  const { address } = useAccount()
  
  const { data, isLoading } = useAccountTransactionHistory({
    chainId: 137,
    accountAddress: address,
  })

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

  return (
    <ul>
      {data?.transactions?.map((tx) => (
        <li key={tx.txnHash}>
          {tx.txnHash} | chain {tx.chainId} | block #{tx.blockNumber}
        </li>
      ))}
    </ul>
  )
}

Intent Transaction History

Retrieve the full transaction history for a specific intent:
import { useIntentTransactionHistory } from '0xtrails'
import { useAccount } from 'wagmi'

export const IntentHistory = ({ intentId }: { intentId: string }) => {
  const { address } = useAccount()

  const {
    transactions,
    loading,
    error,
    refetch,
  } = useIntentTransactionHistory({
    accountAddress: address,
    pageSize: 10,
    enabled: true,
  })

  if (loading) return <div>Loading intent history...</div>
  if (error) return <div>Error: {String(error)}</div>

  return (
    <div>
      <button onClick={refetch}>Refresh</button>
      <ul>
        {transactions?.map((tx) => (
          <li key={tx.txnHash}>
            {tx.txnHash} | {tx.timestamp}
          </li>
        ))}
      </ul>
    </div>
  )
}
For more information, see: