Create Queries and Charts

Use AI to build and execute three new charts on blockchain data!

In this activity, use Space and Time Studio and a few AI prompts to generate both a functioning query and new chart.


Create an AI Query


Create a Chart From Your Data



Rinse, Repeat

If you've followed along above, you should now have a query and chart comparing the TPS of Ethereum and Polygon. See if you can generate two more comparison charts, using the AI prompt (or optionally SQL) below:

Two Week Wallet Count

Let's look at the Wallet count of Ethereum vs Polygon for the same 2 week period:

AI Prompt:

show me a comparison of the count of Ethereum wallets and polygon wallets for last two weeks by date. Include only full days, and call the column Wallet_Date. Make a column for each blockchain. Always limit to 1000 rows.

Click here for help!

In the case below, the AI-SQL elected to generate a query that JOINs the two chains rather than UNIONs. In other words, created a different column for Ethereum and Polygon, instead of having a "Blockchain" column.

--show me a comparison of the count of Ethereum wallets and polygon wallets for last two weeks by date
SELECT 
    e.wallet_date AS wallet_date,
    COALESCE(e.wallet_count, 0) AS ethereum_wallet_count,
    COALESCE(p.wallet_count, 0) AS polygon_wallet_count
FROM (
    SELECT 
        DATE(time_stamp) AS wallet_date,
        COUNT(DISTINCT wallet_address) AS wallet_count
    FROM ETHEREUM.NATIVE_WALLETS
    WHERE time_stamp BETWEEN current_date -14 AND current_date
    GROUP BY DATE(time_stamp)
) e
FULL JOIN (
    SELECT 
        DATE(time_stamp) AS wallet_date,
        COUNT(DISTINCT wallet_address) AS wallet_count
    FROM POLYGON.NATIVE_WALLETS
    WHERE time_stamp BETWEEN current_date -14 AND current_date
    GROUP BY DATE(time_stamp)
) p
ON e.wallet_date = p.wallet_date
ORDER BY e.wallet_date
LIMIT 1000;

This is fine - in fact, having 2 different columns on the same row typically generates great charts with very little adjustment:

Note that the two different Y-axis series (Ethereum and Polygon) may end up on different scales, one on the right axis and one on the left axis. For example, configuring the last chart in the above picture, you'll see there are different scales, one on the right Y-axis (polygon) which goes from 0 to 700k, and one on the left (ethereum) which goes from 0 to 600k:

You can force both Y-axis to appear on the same y-axis, which normalizes the height of the bars to the same scale. To do this, scroll down to the lower-left of the configuration screen, in the "Data" section and change the Y1 "Y1-Axis to Plot" to be on the "right" side.

With a few other tweaks, you can quickly end up with a solid final product:

Don't forget to save your chart and query! To be consistent with the above example, let's use the name:
Wallet Count, ETH vs Poly


Count of ERC20 Tokens

Finally, let's compare ERC20 tokens between Ethereum and Polygon:

show me a comparison in the distinct count of ERC20 tokens on Ethereum and on Polygon, for the last two weeks by date. Add a column called "blockchain" to display the chain name. Always limit to 1000 rows.

Click here for help!

While testing, here is the AI-SQL generated:

--show me a comparison in the distinct count of ERC20 tokens on Ethereum and on Polygon, for the last two weeks by date.
SELECT 
    DATE(e.time_stamp) AS date, 
    COUNT(DISTINCT e.contract_address) AS distinct_token_count, 
    'Ethereum' AS blockchain
FROM 
    ETHEREUM.ERC20_EVT_TRANSFER e
WHERE 
    e.time_stamp BETWEEN current_date -14 and current_date
GROUP BY 
    DATE(e.time_stamp)
UNION ALL
SELECT 
    DATE(p.time_stamp) AS date, 
    COUNT(DISTINCT p.contract_address) AS distinct_token_count, 
    'Polygon' AS blockchain
FROM 
    POLYGON.ERC20_EVT_TRANSFER p
WHERE 
    p.time_stamp BETWEEN current_date -14 and current_date
GROUP BY 
    DATE(p.time_stamp)
ORDER BY 
    date, blockchain
LIMIT 1000;

Note that the AI-SQL engine went back to a UNION approach, meaning there is a "Blockchain" column and rows for Ethereum and Polygon are above/below each other, instead of side-by-side. This is fine, and matches the first example.

If you prefer the side-by-side approach, simply click the "Run Prompt" button again, and the AI-SQL engine will re-generate from prompt. You can ask the AI to regenerate as many times as you want.

Alternatively - tell the AI exactly what you want! For example, you can add to the above prompt:

show me a comparison in the distinct count of ERC20 tokens on Ethereum and on Polygon, for the last two weeks by date. Always limit to 1000 rows.
Make sure there is a column for Ethereum_ERC20_Tokens and a column for Polygon_ERC20_Tokens.

This prompt generated a query more like the second example, with a separate column for each chain. More over, it explicitly used the column names supplied, giving you preemptive control on how the data looks.

Again, don't forget to save your chart and query! To be consistent with the rest, let's use the name:
Token Count, ETH vs Poly



Share Your Work!

The last step is to publish your work to the world! Navigate back to the chart summary page by clicking on the top-most tab "Queries" and "My Visuals". There, you should see the three charts you just created.

Click on one of your graphs to bring it into focus. Beside the "Pin to Dashboard" button is the "Publish Chart" button. Click that, and you'll be prompted to select between:

  • Private (current selection)
  • Private to My Org - this publishes it to anyone within your subscription, but no-one outside your subscription can view
  • Public - anyone can view

Mark your 3 charts as Public so they can be seen and verified by the accreditation process. You'll be prompted for a globally unique chart name - go ahead and name these however you like, and click Publish. You're good to go!



Get Credit:

You'll get credit for this activity if you:

  • Have generated 3 queries and 3 charts, and shared them publicly.

{/ looking for 3 public charts (from API preferably) /}


What’s Next