Indexing and Querying Data

Introduction

Studio Blockchain’s advanced indexing and querying system ensures developers have seamless access to blockchain data for dApp development, analytics, and transaction monitoring. Leveraging a PostgreSQL-backed indexer and comprehensive REST APIs, Studio Blockchain provides real-time and historical data with robust performance enhancements. This guide walks you through the capabilities of the indexer and how to query data effectively.


1. Key Features of the Studio Blockchain Indexer

  1. Dual Connection System:

    • Supports both HTTP and WebSocket connections for data access.

    • Real-time block processing ensures minimal latency.

  2. Optimized Data Storage:

    • Uses PostgreSQL for efficient storage and retrieval of blockchain data.

    • Provides advanced features like pagination and filtering.

  3. Comprehensive REST API:

    • Endpoints to access blocks, transactions, contracts, and addresses.

    • Historical and real-time data available.

  4. Scalability and Performance:

    • AI-enhanced query optimization ensures fast response times.

    • Designed to handle high transaction throughput without bottlenecks.


2. Setting Up the Indexer

The Studio Blockchain indexer requires PostgreSQL as a backend. Follow these steps to set it up:

Step 1: Install PostgreSQL

  1. Install PostgreSQL on your machine:

  2. Start the PostgreSQL service:

Step 2: Configure the Database

  1. Create a new PostgreSQL user and database:

  2. Set a password for the studio-indexer user:

Step 3: Run the Indexer

Clone the Studio Blockchain repository if not done already:

Run the indexer:

Ensure the configuration file (indexer-config.yaml) is correctly set up with your database credentials and network RPC.


3. REST API Endpoints

Studio Blockchain’s REST API provides developers with extensive capabilities for querying blockchain data. Below are the key endpoints:

Block Data

  • Get Latest Block:

    Example Response:

  • Get Block by Number:

    Replace :number with the block number (e.g., /blocks/100).


Transaction Data

  • Get Latest Transactions:

    Example Response:

  • Get Transaction by Hash:

    Replace :hash with the transaction hash.


Address Activity

  • Get Transactions for an Address:

    Replace :address with the wallet address.


Contract Verification

  • Submit Contract for Verification:

    Example Payload:


Health Check

  • Check Indexer Health:

    Example Response:


4. WebSocket for Real-Time Updates

Studio Blockchain’s WebSocket endpoint provides developers with real-time data feeds.

Subscription Example:


5. Querying Gas Usage Metrics

Access block-level gas metrics via the API:

  • Get Gas Usage Statistics:

    Example Response:


6. Best Practices

  1. Efficient Querying:

    • Use pagination for endpoints that return large datasets (e.g., /blocks).

    • Subscribe to WebSocket events for real-time updates instead of polling.

  2. Indexing Custom Data:

    • Extend the indexer to store application-specific data (e.g., NFT metadata or custom token statistics).

  3. Monitoring Indexer Health:

    • Regularly check the /health endpoint for service status and performance metrics.


Next Steps

Now that you understand how to index and query data:

  1. Proceed to explore Ecosystem Development for insights into Studio Blockchain’s broader dApp ecosystem.

  2. Set up real-time data analytics pipelines using WebSocket subscriptions and the REST API.

  3. Contribute to Studio Blockchain by extending the indexer or creating new tools for developers.

Last updated