Skip to main content

Summary

You can write SQL queries spanning all blockchains offered by Allium. Query raw blockchain data for full flexibility, or leverage abstracted data models to get data you care about quickly (e.g. crosschain.dex.trades and crosschain.stablecoin.transfers).

Run a Query

  1. Go to https://app.allium.so/analyze/queries and click on New to create a new query.
  2. Copy and paste the query below into the query editor:
    -- This example query fetches DEX USD volume for
    -- Ethereum, Base, and Solana for the last 10 days
    select
      date(block_timestamp) as date,
      chain,
      sum(usd_amount) as usd_volume
    from crosschain.dex.trades
    where
      block_timestamp >= current_timestamp - interval '10 days'
      and chain in ('ethereum', 'base', 'solana')
    group by all
    order by date asc;
    
  3. Click on Run to execute the query. The results will be shown as a table: Query results table You can switch to chart view and group by chain: Query results chart

Create a Parameterized Query

If you need to run multiple very similar queries, you can do so with parameterized queries. Replace a variable or string in your query with {{param_name}} in the query editor. Example parameterized query:
-- This example parameterized query fetches DEX USD volume for
-- a configurable chain for a configurable number of days
select
  date(block_timestamp) as date,
  chain,
  sum(usd_amount) as usd_volume
from crosschain.dex.trades
where
  block_timestamp >= current_timestamp - interval '{{last_n_days}} days'
  and chain = '{{chain}}'
group by all
order by date asc;
The parameters will automatically be picked up by the query editor. Enter values for them, e.g. 3 for last_n_days and solana for chain, then click on Run to execute the query and view results. Query with parameters You can modify the parameters and re-run the query to get data for different chains and number of days.

Query on a Previous Query Result

You can use the results of a completed query run in another query. This allows you to build up more complex queries, or run additional aggregations or joins on top of data that you have already queried.
  1. Run a query, then on its query editor page, click on View Run History to view completed query runs: Query run history
  2. Click the copy button to copy the relevant run ID.
  3. Use it in a new query as query_history.<query_run_id> . For example, if your query run ID is hoHTRjrs2MO3X64I5Rc2_20251001T080527_horde, you can do:
    select sum(usd_volume)
    from query_history.hoHTRjrs2MO3X64I5Rc2_20251001T080527_horde;
    
If you are querying with a mix of query_history results and Allium’s data tables, you can only use query results that are less than 24 hours old.For queries using only query_history results, there is no time limit.