Run your first query

No need to load data to write queries - explore blockchain data immediately!

❗

Make sure you Connect to Space and Time before moving forward.

Query blockchain data

Now that you've connected to the platform, it's time to run your first query! Space and Time provides access to relational, realtime blockchain data for all users, which means you can start running queries right away.

Run a query via REST API

To run a query via REST API:

  1. Jump over to the API Reference tab
  2. Under the SQL API category, call the Execute queries (DQL) API
  3. Jump to the Sample SQL section on this page for a few sample queries to try

Run a query via JDBC

To run a query via JDBC:

  1. Open your JDBC-compliant application or IDE
  2. Jump to the Sample SQL section on this page for a few sample queries to try

Sample SQL

Below are a few sample queries on blockchain tables to help you get started. You can run these queries using REST APIs or your favorite JDBC-compliant application or IDE.

What Ethereum Exchange has the highest count of trades?

SELECT EXCHANGE_NAME, COUNT(*) 
FROM ETH.DEX_TRADE
GROUP BY EXCHANGE_NAME
ORDER BY 2 DESC

πŸ“˜

Hint: if you're submitting this query through the DQL REST API endpoint, the resourceId parameter should be the namespace plus table name (i.e., ETH.DEX_TRADE).

πŸ‘

You ran your first query!

Let's try another:

What is the content of a given wallet?

SELECT Type AS TokenType, COUNT(*) 
FROM eth.WALLET
JOIN eth.TOKEN_TYPE
  ON WALLET.TOKEN_TYPE_ID = TOKEN_TYPE.ID
WHERE WALLET_ADDRESS = '0x024BCbCAad82E67F721799E259ca60bc7d363419'
GROUP BY TokenType
ORDER BY 2 DESC

πŸ“˜

Try replacing the WALLET_ADDRESS above with your wallet address and see what comes up.

Let's run one more, this time a cross-chain query that compares the number of smart contracts on Ethereum to Avalanche:

-- number of smart contracts on ETH vs AVAX 
SELECT e.Create_Date
,eth_contract_count
,avax_contract_count
,(avax_contract_count*1.00) / (eth_contract_count*1.00) AS eth_avax_pct
FROM
(
SELECT 'eth ' as chain, cast(timestamp as date) AS create_date, COUNT(*) AS eth_contract_count
FROM eth.CONTRACT 
WHERE cast(timestamp as date) = '2022-04-15'
GROUP BY create_date
) AS e 
JOIN 
(
SELECT 'avax' AS chain, cast(timestamp as date) AS create_date, COUNT(*) as avax_contract_count
FROM avax.CONTRACT 
WHERE cast(timestamp as date) = '2022-04-15'
GROUP BY create_date
) AS a 
on e.create_date = a.create_date

What’s Next