> ## 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. onTokenEventsCreated subscription reference: arguments and payload fields.

> **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, Base, and Robinhood (on Base, `processed` returns Flashblocks events).**
>
> For the fastest `processed` data, connect to an [edge node](https://docs.codex.io/concepts/edge-nodes.md).

## GraphQL

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

enum EventCommitmentLevel {
  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!
}

type LiftHarvestFeeData {
  type: String!
  positionId: String!
  quoteAddress: String!
  creatorAddress: String
  quoteToCreator: String!
  quoteToTreasury: String!
  baseBurned: String!
}

type TollyCollectionFeeData {
  type: String!
  positionId: String!
  projectToken: String!
  quoteCollectedRaw: String!
  tokenBurnedRaw: String!
  tollyBuybackRaw: String!
  projectBuybackRaw: String!
  projectBuybackAccruedRaw: String!
  holderRewardsRaw: String!
  protocolRaw: String!
  creatorPaidRaw: String!
  creatorAccruedRaw: String!
}

union SupplementalFeeData = PumpCashbackFeeData | PumpAmmCashbackFeeData | LiftHarvestFeeData | TollyCollectionFeeData

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

type TradeSource {
  id: String!
  displayName: String
}

type CurrencyUnits {
  currency0: String!
  currency1: String!
  decimals0: Int!
  decimals1: Int!
}

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!]
  tradeSource: TradeSource
  currencyUnits: CurrencyUnits
}

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

input OnTokenEventsCreatedInput {
  tokenAddress: String
  networkId: Int!
}
```

### Example

[Test this query in the Explorer →](https://docs.codex.io/explore.md)

```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": "PAIR_ADDRESS:1399811149",
      "events": [
        {
          "eventType": "Swap",
          "eventDisplayType": "Buy",
          "timestamp": 1769561435,
          "blockNumber": 396376317,
          "transactionHash": "4pAiF26PJSxj4qnWGjaFL5tFgV9zGa38sxzcXyzA8MAM7KiviTS4pdqTPoUusPccH3k7VbXWqfoEsqLkkLMzSrkm",
          "maker": "9Fke4xFjBZfUxe54TFbfZyUiWoGF91NB87gbgAqhVrZh",
          "address": "PAIR_ADDRESS",
          "token0Address": "TOKEN_ADDRESS",
          "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
* Each message holds one pool's events from one block, so you receive one message per pool per block.
* Use `eventDisplayType` for human-readable buy/sell labels
* `token0SwapValueUsd` / `token1SwapValueUsd` are the USD price of one unit of each token at the swap, not the trade's value. For the trade's size in USD, use `priceUsdTotal` on `SwapEventData`
* Each event can include a `tradeSource` identifying the app the trade was placed through (swaps on Solana and EVM networks; null for most events, since most trades carry no identifying signal) — see [Trade source](https://docs.codex.io/recipes/events.md#trade-source)

### Troubleshooting Tips

> [accordion] 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] 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] 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] 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`.

### Related Recipes

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


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