Ethereum Data in Chainslake

- 7 mins

In the previous article, you were introduced to organizing tables and how to query data effectively on the Chainslake platform. In this article, I will share about Ethereum data in Chainslake. Understanding Ethereum will help you exploit data from all other EVM blockchains.

Contents

  1. Raw data on Ethereum
  2. Decode data, get information from contract
  3. Build insight tables
  4. Conclusion

Raw data on Ethereum

Raw data on Ethereum includes 3 tables transactions, logs, traces located in the ethereum directory.

Transactions

transactions

This is a table containing information of all transactions on Ethereum, each transaction includes:

Traces

traces

When a contract executes a transaction, it will include many sequential processing steps, these processing steps can call other functions in the same contract or other contracts, these are called internal transactions. The traces table stores information of all internal transactions on Ethereum. Including the following information:

Logs

logs

During execution, a contract can emit events to record changes in the data inside the contract. Data from these events is stored in the logs table. Including the following information:

Note: The logs table only contains events of successful transactions

Decode data, get information from contract

Decode data

Data in the transactions, traces, and logs tables are all encrypted. For example:

To decode this data into a readable form, we need an ABI (Application Binary Interface) that is usually provided with the contract’s source code. Let’s look at an example of an ERC20 contract’s ABI:

[
    {
        "anonymous": false,
        "inputs": [
            {
                "indexed": true,
                "name": "from",
                "type": "address"
            },
            {
                "indexed": true,
                "name": "to",
                "type": "address"
            },
            {
                "indexed": false,
                "name": "value",
                "type": "uint256"
            }
        ],
        "name": "Transfer",
        "type": "event"
    }
]

The result after decoding will get the table ethereum decoded.erc20_evt_transfer below:

erc20_evt_transfer

The table is decoded from the logs table via ABI, you can see other decoded tables in the ethereum_decoded directory

erc20_evt_transfer_diagram

Get information from the contract

For convenience, Chainslake needs to get more information from the contracts after decoding, these information tables are placed in the ethereum_contract folder. For example, the erc20_tokens table below:

erc20_tokens

The table contains information such as name, symbol, total supply of the contract. The contract address is taken from the erc20_evt_transfer table:

erc20_tokens_diagram

Building insight tables

Raw data tables, decoded tables and contract tables are the raw materials that when combined according to a certain logic will form an insight table suitable for data query purposes. I will take the example of the ethereum_balances.token_transfer_hour table:

token_transfer_hour

This is a table containing information about the balance changes of all wallets, all tokens on Ethereum every hour, including the following information:

To build this table we need data from the transactions, traces, erc20_evt_transfer, erc20_tokens tables, the diagram is as follows:

token_transfer_hour_diagram

You can see the Source code of this table after clicking on the image above, I will briefly explain the logic of this table:

frequent_type=hour
list_input_tables=${chain_name}_decoded.erc20_evt_transfer,${chain_name}.traces,${chain_name}.transactions,${chain_name}_contract.erc20_tokens
output_table=${chain_name}_balances.token_transfer_hour
erc20_event_table=${chain_name}_decoded.erc20_evt_transfer
erc20_token_table=${chain_name}_contract.erc20_tokens
transactions_table=${chain_name}.transactions
traces_table=${chain_name}.traces
re_partition_by_range=block_date,key_partition
partition_by=block_date
write_mode=Append
number_index_columns=7

In the header of the Code we have the table configuration including:

In the body of the Code is the table construction logic written in SQL. Transfer token data is taken from the erc20_evt_transfer table, combined with erc20_tokens to get the name, symbol, decimals of the token, then grouped by block_hour, wallet_address, token_address to calculate the number of tokens changing per hour. For Native ETH, it is necessary to take from the traces table (only take successful transactions) and transactions (to get transaction fees).

Conclusion

Although the article is quite long, I have introduced the most important parts of Chainslake’s Ethereum data. I hope that from here you can explore and exploit Chainslake’s data yourself. See you again!

comments powered by Disqus