Query the Cronos blockchain using Google's public BigQuery dataset and Python in Google Colab
Google’s Cronos blockchain dataset is a comprehensive database of Cronos blockchain data, maintained by Google. It contains 4 tables (blocks, transactions, receipts and logs) and encompasses enough blockchain data to cater to most of your analytical needs.
The goal of this blog post is to demonstrate how you can use the public BigQuery dataset to measure the number of monthly active users who interact with the Cronos smart contracts belonging to the VVS Finance protocol.
Setting up your Google Cloud project credentials
In order to perform BigQuery queries in Google Colab, you need to create a service account under a Google Cloud project, and download the JSON containing the account’s credentials. You can follow these steps.
Visit Google Cloud.
Create a new Google Cloud project. You will need to set up billing for your Google Cloud account, if you haven’t already. After creation, don’t forget to select the project so that its name appears in the project box.
Go to IAM & Admin > Service accounts, and create a new service account.
Enter any account name, add the role “BigQuery User”, and click done.
Click on the service account and, under the Keys tab, create a new key in JSON format. The JSON file will be downloaded onto your computer.
Finally, visit Google’s Cronos public BigQuery dataset and enable the BigQuery API in your project.
Executing the query in Google Colab
You can open the Google Colab notebook here and then, under the File menu, you can save a copy in your own Google Drive.
The notebook involves the following steps:
First, past the contents of the Google Cloud service account’s JSON file into the service_account_credentials variable.
Create the BigQuery client using the service account.
Declare the addresses of the smart contracts associated with the VVS Finance protocol.
Perform the query to measure the number of Monthly Active Wallets over the last 30 days.
Don’t forget to keep your service account credentials safe!
After pasting the credentials, you can run the notebook. The result of the query appears at the bottom of the notebook.
Next steps
From there, you can leverage the notebook to create any other data query or data visualization required by your business, marketing, or other stakeholders.