Skip to main content

Making Injective Indexer gRPC Requests with Python

Updated on
Sep 17, 2026

Overview

Python is a high-level programming language known for its readable syntax and extensive package ecosystem. Its gRPC tooling makes it straightforward to generate clients and query blockchain services. Follow the official installation guide to install Python. Verify the installation:

python3 --version
pip3 --version

This guide builds a Python client for the Injective Indexer gRPC API, authenticates with x-token, and calls the Explorer service's GetBlocksV2 method. The completed example requests the latest indexed Mainnet block and prints the protobuf response as JSON.

You will:

  1. Create a virtual environment and install the gRPC libraries.
  2. Download the official Explorer and Exchange proto definitions.
  3. Generate Python client code.
  4. Configure your Quicknode endpoint and token.
  5. Run an authenticated request and verify the response.

Prerequisites

This guide requires Python 3.9 or later with pip and virtual environment support.

Step 1: Create the project

Create a virtual environment and install the gRPC packages:

mkdir injective-indexer-grpc-python
cd injective-indexer-grpc-python
python3 -m venv venv
source venv/bin/activate
pip install grpcio grpcio-tools protobuf
mkdir -p proto/explorer proto/exchange

Step 2: Download the proto definitions

Download the official injective_explorer_rpc.proto and injective_exchange_rpc.proto files:

curl -L \
https://raw.githubusercontent.com/InjectiveLabs/injective-proto/master/all_protos/exchange/injective_explorer_rpc.proto \
-o proto/explorer/injective_explorer_rpc.proto

curl -L \
https://raw.githubusercontent.com/InjectiveLabs/injective-proto/master/all_protos/exchange/injective_exchange_rpc.proto \
-o proto/exchange/injective_exchange_rpc.proto

Step 3: Generate the clients

Generate the Python clients:

python -m grpc_tools.protoc \
-I proto \
--python_out=. \
--grpc_python_out=. \
proto/explorer/injective_explorer_rpc.proto \
proto/exchange/injective_exchange_rpc.proto

touch explorer/__init__.py exchange/__init__.py

Step 4: Configure the endpoint and token

Given an HTTP Provider URL in this format:

https://YOUR_ENDPOINT_NAME.injective-mainnet.quiknode.pro/YOUR_TOKEN/

set the gRPC endpoint and token as environment variables. Injective Indexer gRPC uses TLS on port 443:

export QN_GRPC_ENDPOINT="YOUR_ENDPOINT_NAME.injective-mainnet.quiknode.pro:443"
export QN_TOKEN="YOUR_TOKEN"

Injective Indexer gRPC requires x-token authentication.

x-token authentication

Pass the token as call metadata:

metadata = (("x-token", token),)

Step 5: Create the application

Create main.py. This runnable example uses x-token authentication:

import os

import grpc
from google.protobuf.json_format import MessageToJson
from explorer import injective_explorer_rpc_pb2
from explorer import injective_explorer_rpc_pb2_grpc

ENDPOINT = os.environ["QN_GRPC_ENDPOINT"]
TOKEN = os.environ["QN_TOKEN"]

credentials = grpc.ssl_channel_credentials()
channel = grpc.secure_channel(ENDPOINT, credentials)
client = injective_explorer_rpc_pb2_grpc.InjectiveExplorerRPCStub(channel)
metadata = (("x-token", TOKEN),)

request = injective_explorer_rpc_pb2.GetBlocksV2Request(per_page=1)
response = client.GetBlocksV2(request, metadata=metadata, timeout=20)
print(MessageToJson(response, preserving_proto_field_name=True, indent=2))

channel.close()

Step 6: Run the application

Run the request:

python main.py

Step 7: Verify the response

The request returns the most recently indexed block. Block values change as Injective Mainnet advances, but the response should have this structure. This shortened example is from a live Quicknode response:

{
"paging": {
"next": ["MTgxMDIxMTAw"]
},
"data": [
{
"height": "181021101",
"moniker": "SCV-Security",
"block_hash": "0xd39c44f30e2e45fe5313d9b450e1421f25b88219bc611f493e885dbc58cf07ca",
"num_txs": "3",
"block_unix_timestamp": "1788186602675"
}
]
}

A successful response confirms that TLS, x-token authentication, generated protobuf modules, and the Explorer client are configured correctly.

Next steps

Your Python client is now ready to make authenticated requests to the Injective Indexer gRPC API. Explore the Explorer API methods and Exchange API methods to find more methods, request parameters, response fields, and runnable examples.