Skip to content
midnight-indexer:indexer-service logo

midnight-indexer:indexer-service

Use when querying the Midnight indexer for blockchain data, fetching account balances, listing transactions, reading contract state, or building data-driven DApp backends.

SKILL.md

Full skill instructions

Indexer Service

Connect to and query the Midnight Network indexer for blockchain data including balances, transactions, and contract state.

When to Use

  • Fetching account balances and UTXO data
  • Listing transaction history for an address
  • Reading contract state from the blockchain
  • Querying shielded vs unshielded transaction data
  • Building data-driven DApp backends
  • Implementing pagination for large result sets

Key Concepts

Indexer Architecture

The Midnight indexer provides a GraphQL API for querying blockchain data. It indexes all on-chain activity and exposes it through structured queries.

ComponentPurpose
GraphQL APIQuery interface for blockchain data
WebSocketReal-time subscriptions (see event-subscriptions skill)
REST HealthService health checks

API Versions

The indexer API has evolved through several versions. Ensure your queries are compatible with your target version.

VersionKey FeaturesBreaking Changes
2.0.0Base GraphQL schemaInitial release
2.1.0Enhanced filters, paginationQuery parameter changes
2.1.4Performance optimizationsNone from 2.1.0

UTXO Model

Midnight uses a UTXO (Unspent Transaction Output) model rather than an account model. Balance queries return the set of unspent outputs owned by an address.

Shielded Transactions

Midnight supports both transparent and shielded transactions. The indexer provides different access patterns:

  • Transparent: Full transaction details visible
  • Shielded: Only commitment hashes visible, details encrypted

References

DocumentDescription
api-versions.mdVersion differences and migration guide
query-patterns.mdCommon query patterns and optimization

Examples

ExampleDescription
balance-query/Query account balance and UTXOs
transaction-list/List transaction history with pagination
contract-state/Read deployed contract state

Quick Start

1. Configure Indexer Client

import { createIndexerClient } from '@midnight-ntwrk/​midnight-js-indexer';

const indexer = createIndexerClient({
  uri: 'https://indexer.testnet.midnight.network/​api/​v1/​graphql',
  wsUri: 'wss://indexer.testnet.midnight.network/​api/​v1/​graphql',
});

2. Query Balance

const balance = await indexer.query({
  query: `
    query GetBalance($address: String!) {
      balance(address: $address) {
        total
        utxos {
          txHash
          outputIndex
          amount
        }
      }
    }
  `,
  variables: { address: 'addr_test1...' },
});

console.log('Total balance:', balance.data.balance.total);

3. List Transactions

const transactions = await indexer.query({
  query: `
    query GetTransactions($address: String!, $limit: Int!) {
      transactions(address: $address, first: $limit) {
        edges {
          node {
            hash
            blockNumber
            timestamp
            inputs { address amount }
            outputs { address amount }
          }
        }
        pageInfo {
          hasNextPage
          endCursor
        }
      }
    }
  `,
  variables: { address: 'addr_test1...', limit: 20 },
});

Common Patterns

Environment-Based Configuration

interface IndexerConfig {
  uri: string;
  wsUri: string;
}

function getIndexerConfig(): IndexerConfig {
  const network = process.env.MIDNIGHT_NETWORK || 'testnet';

  const configs: Record<string, IndexerConfig> = {
    testnet: {
      uri: 'https://indexer.testnet.midnight.network/​api/​v1/​graphql',
      wsUri: 'wss://indexer.testnet.midnight.network/​api/​v1/​graphql',
    },
    mainnet: {
      uri: 'https://indexer.midnight.network/​api/​v1/​graphql',
      wsUri: 'wss://indexer.midnight.network/​api/​v1/​graphql',
    },
  };

  return configs[network] ?? configs.testnet;
}

Pagination with Cursors

async function fetchAllTransactions(
  indexer: IndexerClient,
  address: string
): Promise<Transaction[]> {
  const allTransactions: Transaction[] = [];
  let cursor: string | null = null;
  let hasMore = true;

  while (hasMore) {
    const result = await indexer.query({
      query: TRANSACTIONS_QUERY,
      variables: {
        address,
        first: 100,
        after: cursor,
      },
    });

    const { edges, pageInfo } = result.data.transactions;
    allTransactions.push(...edges.map(e => e.node));

    hasMore = pageInfo.hasNextPage;
    cursor = pageInfo.endCursor;
  }

  return allTransactions;
}

Health Check

async function checkIndexerHealth(baseUrl: string): Promise<boolean> {
  try {
    const response = await fetch(`${baseUrl}/​health`);
    return response.ok;
  } catch {
    return false;
  }
}

Retry with Backoff

async function queryWithRetry<T>(
  indexer: IndexerClient,
  query: string,
  variables: Record<string, unknown>,
  maxRetries = 3
): Promise<T> {
  let lastError: Error | null = null;

  for (let attempt = 1; attempt <= maxRetries; attempt++) {
    try {
      return await indexer.query({ query, variables });
    } catch (error) {
      lastError = error as Error;
      if (attempt < maxRetries) {
        await new Promise(r => setTimeout(r, 1000 * attempt));
      }
    }
  }

  throw lastError;
}

Related Skills

  • event-subscriptions - Real-time WebSocket event streams
  • midnight-tooling:contract-calling - Invoking contracts that change state
  • midnight-dapp:state-management - Frontend state synchronization with indexer

Related Commands

  • /​midnight-tooling:check - Verify indexer connectivity

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
Imagica logo
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View