> ## Documentation Index
> Fetch the complete documentation index at: https://docs.solanatracker.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Decode Pump.fun Trades with Yellowstone gRPC

> Subscribe to Pump.fun transactions, decode TradeEvent logs with Anchor, and extract traders, mints, and raw token amounts.

Subscribe to executed Pump.fun transactions and decode `TradeEvent` logs. Each transaction can contain more than one trade event.

Save the [quickstart helper](https://docs.solanatracker.io/yellowstone-grpc/quickstart.md) as `stream.mts` in the same directory. These examples use the same environment variables and dependencies.

## Install the decoder and IDL

```bash theme={null}
npm install @coral-xyz/anchor @solana/web3.js
curl -L https://docs.solanatracker.io/idl/pump.json -o pump.json
```

Use the [bundled Pump.fun IDL](https://docs.solanatracker.io/idl/pump.json) with this example. It supplies the program address, discriminators, and field names; check compatibility when updating it.

## Decode updates

```typescript pump-trades.mts theme={null}
import { readFileSync } from "node:fs";
import { BorshCoder, EventParser, type Idl } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import bs58 from "bs58";
import { subscribe } from "./stream.mts";

const idl = JSON.parse(readFileSync("pump.json", "utf8")) as Idl;
const parser = new EventParser(new PublicKey(idl.address), new BorshCoder(idl));

for await (const update of subscribe({
  transactions: {
    pump: {
      vote: false, failed: false,
      accountInclude: [idl.address], accountExclude: [], accountRequired: [],
    },
  },
})) {
  const transaction = update.transaction?.transaction;
  if (!transaction || transaction.meta?.err) continue;
  try {
    let eventIndex = 0;
    for (const event of parser.parseLogs(transaction.meta?.logMessages ?? [])) {
      const index = eventIndex++;
      if (event.name !== "TradeEvent") continue;
      console.log({
        signature: bs58.encode(transaction.signature),
        slot: update.transaction!.slot,
        eventIndex: index,
        side: event.data.is_buy ? "buy" : "sell",
        mint: event.data.mint.toString(),
        trader: event.data.user.toString(),
        tokenAmountRaw: event.data.token_amount.toString(),
        quoteMint: event.data.quote_mint.toString(),
        quoteAmountRaw: event.data.quote_amount.toString(),
      });
    }
  } catch (error) {
    console.error("Trade event decode failed; check IDL compatibility", error);
  }
}
```

```bash theme={null}
npx tsx pump-trades.mts
```

## Interpret trade events

`EventParser` follows the program invocation stack, so another program’s data logs are not treated as Pump.fun events. Missing or truncated logs can still leave a transaction without a decoded event. Track decode errors and reconcile against transaction history when completeness matters.

Keep raw amounts as strings. Apply the decimals of each mint when displaying values. Use signature plus event index for event-level deduplication; one signature can contain several fills. This example observes trades and does not submit swaps.

## Related guides

> [card] [Pump.fun accounts](https://docs.solanatracker.io/yellowstone-grpc/examples/pumpfun-accounts.md)

> [card] [Reliability and performance](https://docs.solanatracker.io/yellowstone-grpc/best-practices.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.