2. Run your first query

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

This page is part of the Getting Started guide. For the best experience, make sure to follow the guide step-by-step.

Now that you've connected to the platform, it's time to run your first query! We'll walk you through how to run a query using our SQL Operations REST API.

How to run a query

Before we get started, make sure you have the API Reference page open for the Execute Queries (DQL) API.

This API requires two parameters:

  • resourceId: <SCHEMA_NAME>.<TABLE_NAME>- If you're querying more than one table, this will be the first table name you reference. For now, we'll be querying tables of indexed blockchain data already in Space and Time.

For our first query, use this resourceId:

ETHEREUM.ERC721_TRANSFER
  • sqlText: This will be the SQL command (the query) you want to run. Here's a sample query to try:

How many Bored Ape Yacht Club NFTs were transferred on March 9, 2023?

-- BAYC NFTs transfers on March 9, 2023
SELECT COUNT(*)
FROM ETHEREUM.ERC721_TRANSFER
WHERE CONTRACT_ADDRESS = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D' --BAYC
  AND CAST(TIME_STAMP AS DATE) = '2023-03-09'

Here is an example of a cURL request that runs this query:

curl -i --request POST \
     --url "$SxT_DQL_API" \
     --header 'accept: application/json' \
     --header 'authorization: Bearer '"$AT"'' \
     --header 'content-type: application/json' \
     --data @- <<EOF
{
  "resourceId": "ETHEREUM.ERC721_TRANSFER",
  "sqlText": "SELECT COUNT(*) FROM ETHEREUM.ERC721_TRANSFER WHERE CONTRACT_ADDRESS =
'0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D' AND CAST(TIME_STAMP AS DATE) = '2023-03-19'"
}
EOF

In the above request, you will need to replace the$SxT_DQL_API with your Space and Time API URL and the $AT with your Space and Time access_token you generated in step one.

Here's an example of the output. Note that using the -i with the cURL request will give us more info about the response. The 200 is what you want to see.

Now we know there were 606 BAYC NFTs transferred on March 19th, 2023 :rocket:

└─[$] curl -i --request POST \                                                           [9:27:07]
     --url "$SxT_DQL_API" \
     --header 'accept: application/json' \
     --header 'authorization: Bearer '"$AT"'' \
     --header 'content-type: application/json' \
     --data @- <<EOF
{
  "resourceId": "ETHEREUM.ERC721_TRANSFER",
  "sqlText": "SELECT COUNT(*) FROM ETHEREUM.ERC721_TRANSFER WHERE CONTRACT_ADDRESS =
'0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D' AND CAST(TIME_STAMP AS DATE) = '2023-03-19'"
}
EOF
HTTP/2 200 
date: Tue, 28 Mar 2023 15:27:39 GMT
content-type: application/json
content-length: 18
vary: Origin
x-krakend: Version 2.1.1
x-krakend-completed: false
strict-transport-security: max-age=15724800; includeSubDomains

[{"count(1)":606}]                           

👍

You ran your first query!