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

# onTokenEventsCreated

> Live-streamed events for a given token across all it's pools

> **Confirmed vs. unconfirmed events:** Use the `commitmentLevel` argument to choose which events you receive.
>
> * `confirmed` — receive events only after they're confirmed on-chain. This is the default if `commitmentLevel` is not specified.
> * `processed` — receive events as soon as they're observed on-chain (unconfirmed; may be reorged out). You must explicitly set `commitmentLevel: processed` to opt in. **Currently available on Solana only.**

<div data-generated>
  ## GraphQL

  ```
  type Subscription {
    # Requires a Growth or Enterprise plan.
    onTokenEventsCreated(
      input: OnTokenEventsCreatedInput!
      commitmentLevel: [EventCommitmentLevel!]
    ): AddTokenEventsOutput!
  }

  enum EventCommitmentLevel {
    Preprocessed
    Processed
    Confirmed
  }

  enum EventType {
    Burn
    Mint
    Swap
    Sync
    Collect
    CollectProtocol
    PoolBalanceChanged
    LiquidityLock
  }

  type BurnEventData {
    amount0: String
    amount1: String
    amount0Shifted: String
    amount1Shifted: String
    tickLower: String
    tickUpper: String
    type: EventType!
  }

  type MintEventData {
    amount0: String
    amount1: String
    amount0Shifted: String
    amount1Shifted: String
    tickLower: String
    tickUpper: String
    type: EventType!
  }

  type SwapEventData {
    amount0: String
    amount0In: String
    amount0Out: String
    amount1: String
    amount1In: String
    amount1Out: String
    amountNonLiquidityToken: String
    priceBaseToken: String
    priceBaseTokenTotal: String
    priceUsd: String
    priceUsdTotal: String
    tick: String
    type: EventType!
  }

  type PoolBalanceChangedEventData {
    amount0: String
    amount1: String
    amount0Shifted: String
    amount1Shifted: String
    token0: String
    token1: String
    sender: String
    protocolFeeAmount0: String
    protocolFeeAmount1: String
    liquidity0: String
    liquidity1: String
    type: EventType!
  }

  union EventData = BurnEventData | MintEventData | SwapEventData | PoolBalanceChangedEventData

  enum QuoteToken {
    token0
    token1
  }

  enum EventDisplayType {
    Burn
    Mint
    Buy
    Sell
    Sync
    Collect
    CollectProtocol
  }

  enum SandwichLabelForEventType {
    sandwiched
    frontrun
    backrun
  }

  type SandwichLabelForEvent {
    label: String!
    sandwichType: SandwichLabelForEventType!
    token0DrainedAmount: String!
    token1DrainedAmount: String!
  }

  type WashtradeLabelForEvent {
    label: String!
  }

  type LabelsForEvent {
    sandwich: SandwichLabelForEvent
    washtrade: WashtradeLabelForEvent
  }

  type PumpCashbackFeeData {
    type: String!
    cashbackFeeBps: Int!
    cashbackAmountLamports: String!
  }

  type PumpAmmCashbackFeeData {
    type: String!
    cashbackFeeBps: Int!
    cashbackAmountLamports: String!
  }

  union SupplementalFeeData = PumpCashbackFeeData | PumpAmmCashbackFeeData

  type EventFeeData {
    poolFeeRateRaw: String
    poolFeeBps: Float
    poolFeeAmountRaw: String
    dynamicFee: Boolean
    estimatedPoolFee: Boolean
    baseFeeNativeUnit: String
    priorityFeeNativeUnit: String
    gasUsed: String
    builderTipNativeUnit: String
    l1DataFeeNativeUnit: String
    txEventCount: Int
    supplementalFeeData: SupplementalFeeData
  }

  type Event {
    address: String!
    commitmentLevel: EventCommitmentLevel!
    baseTokenPrice: String
    blockHash: String!
    blockNumber: Int!
    data: EventData
    eventType: EventType!
    id: String!
    liquidityToken: String
    logIndex: Int!
    maker: String
    networkId: Int!
    quoteToken: QuoteToken
    timestamp: Int!
    token0Address: String
    token1Address: String
    token0SwapValueUsd: String
    token1SwapValueUsd: String
    token0ValueBase: String
    token1ValueBase: String
    token0PoolValueUsd: String
    token1PoolValueUsd: String
    transactionHash: String!
    transactionIndex: Int!
    supplementalIndex: Int
    eventDisplayType: EventDisplayType
    labels: LabelsForEvent
    feeData: EventFeeData
    walletAge: Int
    walletLabels: [String!]
  }

  type AddTokenEventsOutput {
    id: String!
    events: [Event!]!
  }

  input OnTokenEventsCreatedInput {
    tokenAddress: String
    networkId: Int!
  }
  ```
</div>

### Example

<a href="/explore" target="_blank" rel="noopener noreferrer">Test this query in the Explorer →</a>

```graphql theme={null}
subscription {
  onTokenEventsCreated(
    input: {
      tokenAddress: "So11111111111111111111111111111111111111112"
      networkId: 1399811149
    }
  ) {
    id
    events {
      eventType
      eventDisplayType
      timestamp
      blockNumber
      transactionHash
      maker
      address
      token0Address
      token1Address
      token0SwapValueUsd
      token1SwapValueUsd
      token0ValueBase
      token1ValueBase
      walletAge
      walletLabels
      labels {
        sandwich {
          label
          sandwichType
          token0DrainedAmount
          token1DrainedAmount
        }
      }
    }
  }
}
```

```json Example Response theme={null}
{
  "data": {
    "onTokenEventsCreated": {
      "id": "D9TvhCRcD9JAkA4nfbYH9sUfhcJVzwrhCCj7jgwtD85s:1399811149",
      "events": [
        {
          "eventType": "Swap",
          "eventDisplayType": "Buy",
          "timestamp": 1769561435,
          "blockNumber": 396376317,
          "transactionHash": "4pAiF26PJSxj4qnWGjaFL5tFgV9zGa38sxzcXyzA8MAM7KiviTS4pdqTPoUusPccH3k7VbXWqfoEsqLkkLMzSrkm",
          "maker": "9Fke4xFjBZfUxe54TFbfZyUiWoGF91NB87gbgAqhVrZh",
          "address": "D9TvhCRcD9JAkA4nfbYH9sUfhcJVzwrhCCj7jgwtD85s",
          "token0Address": "FGerXseLVoEsbFtbMAN41V9kc68vJCZxVf1g7NzHBAGS",
          "token1Address": "So11111111111111111111111111111111111111112",
          "token0SwapValueUsd": "0.000055871173472466600153642132795497",
          "token1SwapValueUsd": "126.8383173428749235655594956278139469319",
          "token0ValueBase": "4.4042949909665e-7",
          "token1ValueBase": "1",
          "walletAge": 14513261,
          "walletLabels": null,
          "labels": {
            "sandwich": null
          }
        }
      ]
    }
  }
}
```

### Usage Guidelines

* Pass `tokenAddress` and `networkId` to stream events for a token across **all** its liquidity pools
* Unlike `onEventsCreated` (which subscribes to a single pair), this aggregates swaps from every pool the token trades in
* Each event includes `address` — the pair contract where the swap occurred — so you can identify which pool it came from
* The `events` array may contain multiple events per message
* Use `eventDisplayType` for human-readable buy/sell labels and `token0SwapValueUsd` / `token1SwapValueUsd` for USD values

### Troubleshooting Tips

<AccordionGroup>
  <Accordion title="When should I use onTokenEventsCreated vs onEventsCreated?">
    Use `onTokenEventsCreated` when you want to monitor all trading activity for a token regardless of which pool it happens in. Use `onEventsCreated` when you only care about a specific pair (e.g., SOL/USDC on a particular DEX).
  </Accordion>

  <Accordion title="How do I tell which pool an event came from?">
    Each event includes an `address` field — this is the pair contract address where the swap occurred. You can use this to group or filter events by pool.
  </Accordion>

  <Accordion title="Can I stream events for all tokens on a network?">
    Yes. Omit `tokenAddress` and pass only `networkId` to receive all events across the entire network. This requires an enterprise plan with EventFeed features and is extremely high-volume.
  </Accordion>

  <Accordion title="What event types are included?">
    Events include `Swap`, `Mint`, and `Burn` types. `eventDisplayType` translates these into user-friendly labels like `Buy`, `Sell`, `Add Liquidity`, and `Remove Liquidity`.
  </Accordion>
</AccordionGroup>

### Related Recipes

* [Detailed Token Page](/recipes/detailed-token-page): Build a comprehensive token detail page with price, holders, trades, and real-time updates
* [Events](/recipes/events): Build a token swap list with filtering, pagination, and real-time updates
