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

# Query Templates

> Built-in query templates organized by chain and Cube — load, customize, and execute common on-chain analytical queries

## What Are Query Templates

Query templates are pre-written GraphQL queries that cover the most common analytical use cases across Solana, Ethereum, and BSC. Each template targets a specific Cube and comes pre-filled with the correct query structure, fields, and filter arguments — ready to run after replacing placeholder values.

Templates help you:

* **Learn the schema** by example — see how fields, filters, and ordering work in practice
* **Start quickly** without writing queries from scratch
* **Discover Cubes** you might not have known about

***

## Accessing Templates

<Steps>
  <Step title="Open the sidebar">
    Click the sidebar toggle or press **Ctrl/Cmd+B** to open the left panel.
  </Step>

  <Step title="Select the Queries tab">
    The sidebar has two tabs: **Queries** (templates) and **Saved** (your saved queries). Select **Queries**.
  </Step>

  <Step title="Browse by chain and Cube">
    Templates are organized in a tree: **Chain** (Solana / Ethereum / BSC) → **Cube** (DEXTrades, Transfers, etc.) → **Template**.
  </Step>

  <Step title="Click to load">
    Click any template to load it into the query editor. Placeholder values are highlighted for easy replacement.
  </Step>
</Steps>

***

## Template Organization

Templates follow a two-level hierarchy:

```
Chain (Solana / Ethereum / BSC)
 └── Cube
      └── Template
```

Each chain contains the same set of Cubes and templates, pre-configured with the correct `network` value (`sol`, `eth`, or `bsc`).

***

## Template Catalog

<div style={{ overflowX: 'auto', width: '100%' }}>
  | Cube                   | Templates                                                                  | Count |
  | :--------------------- | :------------------------------------------------------------------------- | :---- |
  | **DEXTrades**          | Latest Trades · Token Trades · Pair Trades · Trades by DEX · Wallet Trades | 5     |
  | **Transfers**          | Token Transfers · Wallet Transfers                                         | 2     |
  | **BalanceUpdates**     | Token Balance Updates · Wallet Balance Updates                             | 2     |
  | **DEXPools**           | Pool Info · Token Pools · Liquidity Snapshots                              | 3     |
  | **TokenSupplyUpdates** | Mint & Burn Events · Market Cap (via TokenSupplyUpdates)                   | 2     |
  | **TokenHolders**       | Top Holders                                                                | 1     |
  | **WalletTokenPnL**     | Wallet PnL                                                                 | 1     |
  | **Pairs**              | Price Candles                                                              | 1     |
  | **Tokens**             | Trade Statistics · Search Tokens (via token dimensions)                    | 2     |
</div>

<Info>
  The most commonly used Cubes are covered across **19 templates**. Each template is available for all supported chains.
</Info>

***

## Template Details by Cube

<AccordionGroup>
  <Accordion title="DEXTrades (5 templates)">
    | Template          | Description                           | Placeholders         |
    | :---------------- | :------------------------------------ | :------------------- |
    | **Latest Trades** | Most recent DEX trades on the network | —                    |
    | **Token Trades**  | Trades involving a specific token     | `TOKEN_ADDRESS`      |
    | **Pair Trades**   | Trades for a specific token pair      | `TOKEN_ADDRESS` (×2) |
    | **Trades by DEX** | Trades filtered by DEX protocol name  | —                    |
    | **Wallet Trades** | All DEX trades executed by a wallet   | `WALLET_ADDRESS`     |
  </Accordion>

  <Accordion title="Transfers (2 templates)">
    | Template             | Description                                | Placeholders     |
    | :------------------- | :----------------------------------------- | :--------------- |
    | **Token Transfers**  | Transfer events for a specific token       | `TOKEN_ADDRESS`  |
    | **Wallet Transfers** | All transfers sent or received by a wallet | `WALLET_ADDRESS` |
  </Accordion>

  <Accordion title="BalanceUpdates (2 templates)">
    | Template                   | Description                                | Placeholders     |
    | :------------------------- | :----------------------------------------- | :--------------- |
    | **Token Balance Updates**  | Balance change events for a specific token | `TOKEN_ADDRESS`  |
    | **Wallet Balance Updates** | All balance changes for a wallet           | `WALLET_ADDRESS` |
  </Accordion>

  <Accordion title="DEXPools (3 templates)">
    | Template                | Description                                    | Placeholders    |
    | :---------------------- | :--------------------------------------------- | :-------------- |
    | **Pool Info**           | Metadata and reserves for a specific pool      | `POOL_ADDRESS`  |
    | **Token Pools**         | All liquidity pools containing a token         | `TOKEN_ADDRESS` |
    | **Liquidity Snapshots** | Historical liquidity data for a pool over time | `POOL_ADDRESS`  |
  </Accordion>

  <Accordion title="TokenSupplyUpdates (2 templates)">
    | Template               | Description                                     | Placeholders    |
    | :--------------------- | :---------------------------------------------- | :-------------- |
    | **Mint & Burn Events** | Mint and burn events affecting a token's supply | `TOKEN_ADDRESS` |
    | **Market Cap**         | Market capitalization snapshot for a token      | `TOKEN_ADDRESS` |
  </Accordion>

  <Accordion title="TokenHolders (1 template)">
    | Template        | Description                                    | Placeholders    |
    | :-------------- | :--------------------------------------------- | :-------------- |
    | **Top Holders** | Largest holders of a specific token by balance | `TOKEN_ADDRESS` |
  </Accordion>

  <Accordion title="WalletTokenPnL (1 template)">
    | Template       | Description                                         | Placeholders                      |
    | :------------- | :-------------------------------------------------- | :-------------------------------- |
    | **Wallet PnL** | Realized and unrealized PnL for a wallet-token pair | `WALLET_ADDRESS`, `TOKEN_ADDRESS` |
  </Accordion>

  <Accordion title="Pairs (1 template)">
    | Template          | Description                                     | Placeholders    |
    | :---------------- | :---------------------------------------------- | :-------------- |
    | **Price Candles** | OHLC candlestick data at configurable intervals | `TOKEN_ADDRESS` |
  </Accordion>

  <Accordion title="Tokens (2 templates)">
    | Template             | Description                                             | Placeholders    |
    | :------------------- | :------------------------------------------------------ | :-------------- |
    | **Trade Statistics** | Aggregated trade volume, count, and unique traders      | `TOKEN_ADDRESS` |
    | **Search Tokens**    | Full-text search for tokens by name, symbol, or address | —               |
  </Accordion>
</AccordionGroup>

***

## Placeholders

Templates use uppercase placeholders to indicate values you need to replace with real on-chain addresses before executing.

| Placeholder      | Description                 | Example                                                         |
| :--------------- | :-------------------------- | :-------------------------------------------------------------- |
| `TOKEN_ADDRESS`  | Token contract/mint address | `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v` (USDC on Solana) |
| `WALLET_ADDRESS` | Wallet public address       | `5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1`                  |
| `POOL_ADDRESS`   | DEX liquidity pool address  | `58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2`                  |

<Note>
  Placeholders appear as literal strings in the query (e.g. `MintAddress: {is: "TOKEN_ADDRESS"}`). Replace the entire placeholder string including quotes with your actual address.
</Note>

***

## Example: Using a Template

Here's how to use the **DEXTrades → Latest Trades** template on Solana:

<Steps>
  <Step title="Open sidebar and select template">
    Navigate to **Solana → DEXTrades → Latest Trades** and click to load.
  </Step>

  <Step title="Review the loaded query">
    The editor populates with:

    ```graphql theme={null}
    query {
      Solana {
        DEXTrades(
          limit: {count: 10}
          orderBy: {descending: Block_Time}
        ) {
          Block { Time Slot }
          Transaction { Hash }
          Trade {
            Buy {
              Currency { MintAddress Symbol Name }
              Amount
              PriceInUSD
            }
            Sell {
              Currency { MintAddress Symbol Name }
              Amount
            }
            Dex { ProtocolName }
          }
        }
      }
    }
    ```
  </Step>

  <Step title="Execute">
    This template has no placeholders — it fetches the 10 most recent trades. Press **Ctrl/Cmd+Enter** to run.
  </Step>

  <Step title="Iterate">
    Modify the query to add filters, change the limit, or select different fields. The schema autocomplete helps you discover available options.
  </Step>
</Steps>
