Run a query

Run a query using the Space and Time dapp, REST APIs, or JDBC driver.

📘

For a step-by-step tutorial on how to run your first query with example code included, visit the Run your first query page.

Queries in Space and Time

You can run SQL queries against:

  • Your own tables in Space and Time, containing off-chain data that you've ingested
  • Tables containing relational, realtime blockchain data that we've indexed from major chains

For more information on writing SQL, visit the Writing SQL page.

You can run a query using our SQL APIs or using our JDBC driver.

Example Queries

What is the content of a given wallet?

  • resourceId: ETHEREUM.NATIVE_WALLET

  • sqlText:

SELECT Type AS TokenType, COUNT(*) 
FROM ETHEREUM.NATIVE_WALLET
JOIN ETHEREUM.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.

  • resourceId: ETHEREUM.CONTRACT
  • sqlText:
-- 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 ETHEREUM.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 AVALANCHE_C.CONTRACT 
WHERE cast(timestamp as date) = '2022-04-15'
GROUP BY create_date
) AS a 
on e.create_date = a.create_date