// documentation

learn how to use tx-indexer

under construction

installation

npm

npm install tx-indexer

bun

bun add tx-indexer

yarn

yarn add tx-indexer

pnpm

pnpm add tx-indexer

quick start

import { createIndexer } from "tx-indexer";

const indexer = createIndexer({ 
  rpcUrl: "https://api.mainnet-beta.solana.com" 
});

// Get wallet balance
const balance = await indexer.getBalance("YourWalletAddress...");

// Get classified transactions
const txs = await indexer.getTransactions("YourWalletAddress...", {
  limit: 10,
  filterSpam: true
});

// Get single transaction
const tx = await indexer.getTransaction("signature...");

// Access classification
console.log(tx.classification.primaryType); // "transfer", "swap", etc.
console.log(tx.classification.sender);
console.log(tx.classification.receiver);

API reference

createIndexer(options)

Creates a new indexer instance.

Options:

  • rpcUrl: string - Solana RPC endpoint
  • wsUrl?: string - Optional WebSocket URL
  • client?: SolanaClient - Pre-configured client

getBalance(walletAddress, tokenMints?)

Fetches wallet balance including SOL and specified tokens.

getTransactions(walletAddress, options?)

Fetches and classifies transactions for a wallet.

Options:

  • limit?: number - Number of transactions (default: 10)
  • filterSpam?: boolean - Filter spam (default: true)
  • enrichNftMetadata?: boolean - Fetch NFT metadata (default: true)

getTransaction(signature, options?)

Fetches and classifies a single transaction by signature. Returns null if not found.

getRawTransaction(signature)

Fetches raw transaction data without classification.

transaction types

transfer

Wallet-to-wallet transfers

swap

Token exchanges (any DEX)

nft_mint

NFT minting

stake_deposit

SOL staking deposits

stake_withdraw

SOL staking withdrawals

bridge_in

Receiving from bridge

bridge_out

Sending to bridge

airdrop

Token distributions

fee_only

Only network fees

solana_pay

Solana Pay payments

examples

get wallet transaction history

const txs = await indexer.getTransactions(walletAddress, {
  limit: 20,
  filterSpam: true,
  spamConfig: {
    minSolAmount: 0.001,
    minTokenAmountUsd: 0.01,
  }
});

check if transaction is a swap

const tx = await indexer.getTransaction(signature);
if (tx?.classification.primaryType === "swap") {
  const from = tx.classification.primaryAmount;
  const to = tx.classification.secondaryAmount;
  console.log(`Swapped ${from.amountUi} ${from.token.symbol} for ${to.amountUi} ${to.token.symbol}`);
}

frontend perspective handling

const tx = await indexer.getTransaction(signature);
const connectedWallet = wallet?.address;

if (connectedWallet === tx.classification.sender) {
  // "You sent..."
} else if (connectedWallet === tx.classification.receiver) {
  // "You received..."
}

RPC compatibility

Core features (transactions, balances, classification) work with any Solana RPC.

NFT metadata enrichment requires a DAS-compatible RPC (Helius, Triton, etc.). If using a standard RPC, disable it:

const txs = await indexer.getTransactions(address, {
  enrichNftMetadata: false
});

bundle size

ImportSize (minified + brotli)
Full SDK11.34 KB
createIndexer only11.34 KB
classifyTransaction6.39 KB
fetchTransaction7.39 KB
transactionToLegs7.3 KB

need more help? check out the repository

view on github →