Help & Support

BigQuery Usage Examples

Learn how to interact with Lens Network datasets using different programming languages and tools.

Python

Using the official Google Cloud client library:

from google.cloud import bigquery
# Initialize the clientclient = bigquery.Client()
# Query recent publicationsquery = """SELECT     address,FROM `lens-public-data.testnet_block_explorer_public.addresses` addressesWHERE LIMIT 5"""
# Execute the queryquery_job = client.query(query)
# Process resultsfor row in query_job:    print(f"Handle: {row.handle}, Posted at: {row.block_timestamp}")

Node.js

Using the @google-cloud/bigquery package:

const {BigQuery} = require('@google-cloud/bigquery');
async function queryLens() {  const bigquery = new BigQuery();
  const query = `    SELECT *    FROM \`lens-public-data.testnet_block_explorer_public.transactions\`    ORDER BY createdAt DESC LIMIT 10  `;
  const [rows] = await bigquery.query(query);  console.log('Latest 10 transactions:', rows);}

REST API

Using the BigQuery REST API:

curl -X POST \  -H "Authorization: Bearer $(gcloud auth print-access-token)" \  -H "Content-Type: application/json" \  https://bigquery.googleapis.com/bigquery/v2/projects/lens-public-data/queries \  -d '{    "query": "SELECT COUNT(*) as total_addresses FROM `lens-public-data.testnet_block_explorer_public_.addresses`"  }'

Common Query Examples

Get lastest transactions

SELECT * FROM public.transactions order by "createdAt" desc limit 10;

Remember to handle authentication appropriately in your applications. For local development, you can use the Google Cloud CLI.