Skip to content

Blocks and time ​

CQL answers every row at one block, and at is how you choose which block.

A chain has no clock but its blocks, so a query says where in the chain to look before it says what to look at. This page covers:

  • the four ways to say it
  • what CQL does with latest
  • how a step turns a range into a time series
  • why two runs a minute apart can disagree

The four forms of at ​

  • at latest — the newest block. A state source with no at means this.
  • at 26_000_000 — one block by number. Underscores are for your eyes only.
  • at 25_800_000..26_000_000 — a block range, both ends included. latest-7200 counts backward from the head. finalized is the newest block that the chain will not reorganise.
  • at time '2026-09-20'..'2026-09-23' — a range by timestamp, which CQL resolves to blocks for you. A date alone means midnight UTC, and a full ISO time ('2026-09-20T12:00:00Z') works too.

The last form, with a step, is the one that reads a value once a day:

cql
let stETH = ethereum:0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84;

from stETH at time '2026-09-20'..'2026-09-23' every 1d as s
| project { day: $sampleAt, block: $block, ethPerShare: format(s.getPooledEthByShares(1e18), 18) }

Open in workbench →

dayblockethPerShare
2026-09-20T00:00:00Z260149981.244406447835658845
2026-09-21T00:00:00Z260221691.244482479264728163
2026-09-22T00:00:00Z260293151.24455806764908769
2026-09-23T00:00:00Z260364631.244633419602089156
ethPerShare by dayA step line of ethPerShare over day, from all 4 rows the query returned.1.244451.244501.244551.24460ethPerShare00:002026-09-2012:0000:002026-09-2112:0000:002026-09-2212:0000:002026-09-23day (UTC)2026-09-20T00:00:00Z ethPerShare 1.2444064478356588452026-09-21T00:00:00Z ethPerShare 1.2444824792647281632026-09-22T00:00:00Z ethPerShare 1.244558067649087692026-09-23T00:00:00Z ethPerShare 1.244633419602089156
ethPerShare by dayA step line of ethPerShare over day, from all 4 rows the query returned.1.244451.244501.244551.24460ethPerShare2026-09-202026-09-22day (UTC)2026-09-20T00:00:00Z ethPerShare 1.2444064478356588452026-09-21T00:00:00Z ethPerShare 1.2444824792647281632026-09-22T00:00:00Z ethPerShare 1.244558067649087692026-09-23T00:00:00Z ethPerShare 1.244633419602089156

Each row after the first is the last block before a midnight. The first row is where the range starts: the first block at or after its midnight. The share rate changes exactly once from each row to the next, because stETH rebases once a day.

An event source with no at reads a recent window: the last 10 000 blocks on Ethereum, and a larger window on faster chains. It tells you which window in the run's diagnostics (CQL3901).

latest is pinned when the run starts ​

The moment you press Run, CQL reads the head of every chain the query touches and pins it. latest means that block for the whole run, however long the run takes, and so does the end of any range written against it. This is why a query can make thousands of calls and still describe one consistent moment.

It is also why two runs a minute apart return different rows: the pin moved. If you need the same rows back, ask for a block by number. See Getting the same rows twice.

CQL refuses a block beyond the pinned head rather than waiting for it. For example, at 99_000_000 on a chain at block 26 million reads CQL3001 · ethereum block 99000000 is beyond the pinned head 26042707. The one clamp is a time range whose end is in the future. CQL shortens that range to end at the head and reports it as CQL3902.

A range is a time series when you give it a step ​

A range of state rows reads the contract at every block in it, which is rarely what you want. Add every to sample:

  • every 7200 reads at every block number divisible by 7 200 inside the range, plus the range end. The grid is absolute: every 100 lands on …25_800_000, 25_800_100… whatever block the range starts at. So two queries with the same step align.
  • every 1d reads at every day boundary inside a time range, again plus the end, as the query above does. The units are s, m, h, d and w, so every 1h is an hour.

If a long range has no every, CQL chooses a step for you so that the source stays under 10 000 rows. It says so (CQL3900). On a time range, CQL can choose the step only when the run finds the blocks of the range. So the run gives this note, not the check before the run. The run also checks the caps of a time range at that time. Long ranges and limits has the rule.

every belongs to a range of state rows. On a single block or an event source, it is an error (CQL3005). CQL never samples events.

Two timestamps ​

A sampled row carries two times, and they answer different questions:

  • $timestamp is the timestamp of the block that answered the row.
  • $sampleAt is the boundary that selected the row. For every 1d, that is the exact midnight, as in the day column above. It is null on a row that was not sampled.

Use $sampleAt to put two series on one clock. Their blocks can land seconds apart, and on two chains the block numbers are different, but their boundaries are identical. bin($sampleAt, 1h) is the idiom, and Compare a contract across chains shows it.

Turning a time into a block yourself ​

blockat(chain, t) gives the last block at or before an instant. You can use it anywhere that CQL expects a block. For example, with { block: blockat($chain, $timestamp - 1d) } reads a value from a day before each row. A time before the chain's first block gives null.

See also ​