Query data in Chainslake

- 5 mins

In the previous article you learned about the basic architecture of Chainslake platform. In this article we will learn how to organize data tables in Chainslake and how to query effectively.

Content

  1. Write your first query
  2. Data governance
  3. How to query effectively
  4. Conclusion

Write your first query

Chainslake uses SQL (Sequence Query Language) to query data. If this is your first time learning SQL, it’s okay because each query will have a detailed explanation below. For example:

select * from ethereum.transactions limit 10
  • The query starts with the keyword select to request columns in the table, the * sign means to get all columns of the table
  • The keyword from is used to identify the table to get data through the table name, in this example it is the table ethereum.transactions.
  • The keyword limit is used to limit the number of rows (records) returned in the result.
  • The meaning of the above query is to return 10 records in the table ethereum.transactions

Click on the image below to go to Chainslake’s Metabase page (you will need to login or register for an account). Click the Run query button (or Ctrl + Enter) to execute this query.

Dataflow

Note: Chainslake table names consist of a directory and a name separated by a .. You can start exploring Chainslake’s data tables here.

Tips: You can view queries shared by other users on their personal pages or here by clicking on the charts to go to the Metabase page, select OPEN EDITOR to view the queries.

Data governance

The data tables are arranged in folders according to their meaning, each table is the result of a data transformation from one or more previous tables. As shared in the previous article, the data taken from the blockchain nodes after going through the transformation steps including decoding, filtering, and aggreating will obtain insight data.

To understand better, I will take an example of the table bitcoin_balances.utxo_latest_day, this table is built to easily calculate the balance of any bitcoin wallet.

bitcoin_balances

First of all, I will briefly explain the concept of UTXO (Unspent Transaction Output) in Bitcoin:

Back to the bitcoin_balances.utxo_latest_day table, this table contains the UTXO information of all Bitcoin wallets until 0:00 on the current day. Its columns include:

The data flow diagram for constructing the bitcoin_balances.utxo_latest_day table is as follows:

bitcoin_balances_flow

Tip: on the page data.chainslake.com, for each table you can not only see the description and columns of the table, but also see the source code that creates that table.

How to write the queries effectively

Because it contains the entire Blockchain transaction history, Chainslake’s data tables all have a very large number of records, but the tables have been partitioned and indexed reasonably by date and time, so I have some notes for you when writing queries as follows:

Conclusion

In this article, I hope to help you better understand how Chainslake organizes and queries data. In the next article, we will learn about Ethereum data as well as all EVM blockchains. See you again!

comments powered by Disqus