// documentation
learn how to use tx-indexer
installation
npm
npm install tx-indexerbun
bun add tx-indexeryarn
yarn add tx-indexerpnpm
pnpm add tx-indexerquick 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 endpointwsUrl?: string- Optional WebSocket URLclient?: 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
transferWallet-to-wallet transfers
swapToken exchanges (any DEX)
nft_mintNFT minting
stake_depositSOL staking deposits
stake_withdrawSOL staking withdrawals
bridge_inReceiving from bridge
bridge_outSending to bridge
airdropToken distributions
fee_onlyOnly network fees
solana_paySolana 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
| Import | Size (minified + brotli) |
|---|---|
| Full SDK | 11.34 KB |
| createIndexer only | 11.34 KB |
| classifyTransaction | 6.39 KB |
| fetchTransaction | 7.39 KB |
| transactionToLegs | 7.3 KB |
need more help? check out the repository
view on github →