Beginner⏱ 15 min5 steps

Write Your First On-chain SQL Query

Learn on-chain SQL from scratch: write a ClickHouse query that counts new Uniswap pools created per day, run it, chart it, and save the result.

Wevr Guides ·

SQL has a reputation as a gatekeeper skill — something you earn after years of spreadsheets and internships. In on-chain work, the opposite is true: it is the shortest path from a question to an answer. If you have ever wondered how often something happens on a blockchain, a query answers it in seconds, and the skill transfers to every table you will ever open.

This lesson takes you from zero to your first working query. You will write one real query against decoded on-chain data, understand every clause in it, run it, turn the result into a chart, and save it so it stays one click away forever.

The question we will answer

A good first query answers something you actually want to know, using data that lives in a single table. Ours: how many new liquidity pools did Uniswap create on Ethereum each day over the last six months?

It is a genuine analyst question — pool creation tracks where liquidity deployers expect activity — and answering it needs exactly one table and six short clauses. No joins, no subqueries, nothing exotic.

Meet the table

On Wevr, the query engine speaks ClickHouse SQL over decoded events. "Decoded" is the important word: instead of raw hexadecimal logs, contract events have been parsed into clean, named columns across more than 50TB of activity. You query the event the way the developer designed it, not the way the chain stores it.

The table we need is called uniswap_evt_paircreated. Each row is one PoolCreated event, emitted by the Uniswap factory contract on Ethereum every time somebody deploys a new pool. Alongside the decoded fields, every events table carries the standard columns — most importantly block_timestamp, the moment the chain recorded the event, exact to the second.

If you want to see what else is available before committing to a query, the tables catalog on Wevr lists the decoded tables you can query — browsing it for ten minutes is a genuinely good way to get ideas.

The query, line by line

Here is the whole thing:

SELECT
  toDate(block_timestamp) AS day,
  count() AS pairs_created
FROM uniswap_evt_paircreated
WHERE block_timestamp >= subtractMonths(now(), 6)
GROUP BY day
ORDER BY day

Six clauses, six jobs:

  1. SELECT toDate(block_timestamp) AS day — block_timestamp is exact to the second, which is more precision than our question needs. toDate() truncates each timestamp to its midnight, so every event on the same day collapses to the same value. AS day gives the resulting column a friendly name.
  2. count() AS pairs_created — for each group of rows, count() counts them. Since one row is one pool creation, the count is exactly the number of pools created that day.
  3. FROM uniswap_evt_paircreated — the decoded table we just met.
  4. WHERE block_timestamp >= subtractMonths(now(), 6) — the time filter. now() is evaluated when the query runs; subtractMonths(now(), 6) walks the clock back six months; >= keeps every event from that moment onward.
  5. GROUP BY day — the clause that makes the count meaningful. It gathers all rows sharing the same day into one group, so count() has a bucket to count.
  6. ORDER BY day — the result in chronological order, so the six-month story reads left to right.

Read the clauses bottom-up and you get the question in plain English: from all Uniswap pool creations in the last six months, count the events per day and sort by day. That translation habit — query to sentence, sentence to query — is the real skill; the syntax is just vocabulary.

Run it, chart it, save it

Time to execute. Open the query editor on Wevr.ai, paste the query, and run it. Your first result lands as a table: one row per day, two columns — day and pairs_created.

Three things to do before closing the tab:

  1. Read it as a table first. Scan the values. Which days stand out? Are there quiet stretches, bursts, or a slow drift? A minute of scanning builds the intuition that makes the chart meaningful rather than decorative.
  2. Turn it into a chart. The editor can visualize a result — put day on the x-axis and pairs_created as a series. The six-month shape that was buried in rows becomes obvious at a glance: quiet weeks, busy days, gradual trends.
  3. Save it. Name the query something you will recognize in a month. Because subtractMonths(now(), 6) always moves with the clock, a saved query is not a frozen snapshot — re-run it any time for a fresh six-month window.

That run-chart-save loop is the daily rhythm of on-chain analysis. Everything after your first query is a variation on the same loop.

Where to go next

Modify with intent, one change at a time:

  • Change the window. Swap subtractMonths for subtractDays to zoom into recent weeks.
  • Add a filter. Extend the WHERE clause with another condition to isolate a specific token, contract, or sender — each condition joins the existing one with AND.
  • Point at a different table. Every decoded event table on the platform queries the same way, so the query you just wrote is a template, not a one-off.
  • Go cross-chain. The engine works across the chains Wevr supports, so once one table makes sense, the rest feel familiar.

The barrier that makes SQL feel intimidating is almost never the language — it is the blank editor. You now have something to put in it: a working query where every clause is a pattern you will reuse forever.

Open the editor, paste the example, and press run. The whole lesson — table, editor, chart, and save — lives on the free tier, so your first result is about two minutes away.