> ## 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.

# onEventsCreated

> Live-streamed transactions for a pair.

> **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.
    onEventsCreated(
      address: String
      id: String
      commitmentLevel: [EventCommitmentLevel!]
      quoteToken: QuoteToken
      networkId: Int
      maker: String
    ): AddEventsOutput
  }

  enum QuoteToken {
    token0
    token1
  }

  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 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 AddEventsOutput {
    address: String!
    networkId: Int!
    id: String!
    quoteToken: QuoteToken
    events: [Event]!
  }
  ```
</div>

### Example

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

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

```json Example Response theme={null}
{
  "data": {
    "onEventsCreated": {
      "address": "BGm1tav58oGcsQJehL9WXBFXF7D27vZsKefj4xJKD5Y",
      "networkId": 1399811149,
      "id": "BGm1tav58oGcsQJehL9WXBFXF7D27vZsKefj4xJKD5Y:1399811149",
      "quoteToken": "token0",
      "events": [
        {
          "eventType": "Swap",
          "eventDisplayType": "Sell",
          "timestamp": 1769560515,
          "blockNumber": 396374007,
          "transactionHash": "4EqnQCBDP9AgyKjQu3B7SzFUP6MRXBQWiLGb3b1yqFQQFieamW9B5u3DsH6Ds7KpCfojjxkw27c2izY3xts1A8zx",
          "maker": "7zujqoQsFic14ncDYhBSVGvDnqc94rE49c1ZJCHvAtiW",
          "token0Address": "So11111111111111111111111111111111111111112",
          "token1Address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
          "token0SwapValueUsd": "126.529818076092595016837547037910922",
          "token1SwapValueUsd": "0.99969429999999993936190205232353184",
          "token0ValueBase": "1",
          "token1ValueBase": "0.0078957792081491622",
          "walletAge": 14494714,
          "walletLabels": null,
          "labels": {
            "sandwich": null
          }
        }
      ]
    }
  }
}
```

### Usage Guidelines

* Subscribe by `id` (format `pairAddress:networkId`) to stream transactions for a specific pair
* Alternatively, use `address` + `networkId` to identify the pair, or just `networkId` to stream all events on a network
* Set `quoteToken` to `token0` or `token1` to control which token is treated as the base for display
* `eventDisplayType` provides a human-readable label (`Buy`, `Sell`) relative to the `quoteToken`
* Use `token0SwapValueUsd` / `token1SwapValueUsd` for the USD value of each side of the swap
* `labels` includes MEV detection (e.g., sandwich attacks) for transaction quality assessment
* `walletAge` returns the age of the maker wallet in seconds, useful for filtering out new wallets

### Troubleshooting Tips

<AccordionGroup>
  <Accordion title="What's the difference between eventType and eventDisplayType?">
    `eventType` is the raw on-chain event (e.g., `Swap`, `Mint`, `Burn`). `eventDisplayType` is a user-friendly label relative to the `quoteToken` — for example, a `Swap` is displayed as `Buy` or `Sell` depending on which direction the trade went for the quote token.
  </Accordion>

  <Accordion title="Can I stream events for all pairs on a network?">
    Yes. Pass only `networkId` without an `address` or `id` to receive all events across a network. This is high-volume — use it with caution or filter client-side.
  </Accordion>

  <Accordion title="What do the labels fields indicate?">
    `labels` provides MEV and behavioral detection. The `sandwich` field indicates whether a transaction is part of a sandwich attack — `sandwichType` identifies it as `frontrun`, `backrun`, or `sandwiched`, and `token0DrainedAmount` / `token1DrainedAmount` show how much value was extracted.
  </Accordion>

  <Accordion title="How does quoteToken affect the response?">
    `quoteToken` determines the perspective of `eventDisplayType`. For example, in a SOL/USDC pair where SOL is `token0`, setting `quoteToken: token0` means buying SOL shows as `Buy` and selling SOL shows as `Sell`.
  </Accordion>
</AccordionGroup>

### Related Recipes

* [Events](/recipes/events): Build a token swap list with filtering, pagination, and real-time updates
