Skip to main content

Building GraphQL Queries on Bitquery: First Query to Aggregates

Every Bitquery query has the same shape: a root for the chain or the Trading family, a cube for the kind of fact, a where filter, an orderBy, a limit, and a selection of fields or metrics. Learn that shape once and it carries across every chain and cube. This section takes you from a first query to aggregates and history in four steps: query principles and filters, datasets that decide how far back you reach, metrics that turn rows into numbers, and the schema reference for field names. Everything runs in the Bitquery IDE on a free account.

Read in this order

StepGuideWhat you get
1Query principlesThe root, cube, filter and selection structure
2Query filters, date and time filters, relative timeNarrowing rows by address, token, amount and time
3Dataset options, realtime, archive, combinedHow far back a query can reach and how fresh it is
4Metrics overview, count, sum, uniq, quantile, conditional metricsAggregates, conditions and statistics
5Sorting, limits, indexed fields, optimizing queriesFast, well-formed queries
6EVM schema referenceExact field names per cube

The data coverage and retention page answers "how far back does the data go" per cube and chain, and the capabilities section covers joins, calculations, JSON filters and subscriptions.

A first query

The five most recent transfers on Ethereum: one root, one cube, an order and a limit.

{
EVM(network: eth) {
Transfers(limit: { count: 5 }, orderBy: { descending: Block_Time }) {
Block {
Time
}
Transfer {
Amount
Currency {
Symbol
}
Sender
Receiver
}
}
}
}

From here, add a where to pick one token or one wallet, replace the field list with count and sum(of: Transfer_Amount) to aggregate, add dataset: archive to the root to reach history, or change query to subscription to stream new transfers.

The four groups in this section

Frequently Asked Questions

What does a Bitquery GraphQL query look like?

A root such as EVM(network: eth), Solana or Trading, then a cube such as Transfers or DEXTrades, then where, orderBy and limit arguments, then the fields or metrics you want back. The same shape works on every chain.

How do I query historical data?

Add dataset: archive or dataset: combined to the chain root. Without it a query uses the realtime window, which is short. The data coverage page lists how far back each cube reaches.

How do I count or sum instead of listing rows?

Replace fields with metrics: count, sum(of: ...), uniq(of: ...), quantile and others. Metrics accept an if condition and can be sorted with orderBy descendingByField on an alias.

Where do I find the exact field names?

In the schema reference pages for each EVM cube and in the builder-terms pages for EVM and Solana, or in the IDE, which autocompletes fields as you type.

Do I need an API key to try queries?

Not in the IDE: a free account runs every example. To call the API from code, create an access token at account.bitquery.io.

Build with Bitquery

Ready to run this in production?

Get an API key and run these queries in minutes, or talk to us about plans and enterprise delivery.