Configuration

Configuration

The Open Ethereum Indexer provides a flexible configuration system that allows you to customize the behavior of your indexer. This page explains the configuration structure and available options.

Configuration Structure

The complete type definition for the indexer configuration:

interface NetworkConfig {
  rpcUrl: string; // JSON-RPC endpoint URL
  chainId: number; // Chain ID (e.g., 1 for Ethereum mainnet)
}
 
interface ContractConfig {
  abi: ABI; // Contract ABI
  address?: string; // Optional contract address (not needed for wildcard events)
  startBlock?: number; // Block to start indexing from
  endBlock?: number; // Block to stop indexing at
  excludeEvents?: string[]; // Event names to exclude from indexing
}
 
interface IndexerConfig {
  indexer: {
    network: NetworkConfig;
    contracts: {
      [contractKey: string]: ContractConfig;
    };
  };
  database: {
    migrations?: (string | Function)[]; // Database migration scripts to apply
  };
  app?: {
    disableRootController?: boolean; // Disable main API endpoints
    disableBlockMonitorController?: boolean; // Disable block monitor endpoints
    disableMetrics?: boolean; // Disable Prometheus metrics
    disablePino?: boolean; // Disable Pino logging
  };
}

Here's an example configuration using all available options:

import { IndexerConfig } from '@open-ethereum/indexer';
import ContractABI from './abi/contract.json';
import { InitialSchema } from './migrations/InitialSchema';
 
export const indexerConfig: IndexerConfig = {
  indexer: {
    network: {
      rpcUrl: process.env.NODE_RPC_URL,
      chainId: parseInt(process.env.NODE_CHAIN_ID),
    },
    contracts: {
      // Standard contract with address
      MyContract: {
        abi: ContractABI,
        address: '0x123...',
        startBlock: 1234567,
        endBlock: 1234567,
        excludeEvents: ['EventToIgnore'],
      },
    },
  },
  database: {
    migrations: [InitialSchema],
  },
  app: {
    disableRootController: false,
    disableBlockMonitorController: false,
    disableMetrics: false,
    disablePino: false,
  },
};

Environment Variables

You can use environment variables to configure your indexer. Define these in a .env file:

# Network configuration
NODE_RPC_URL="https://eth-mainnet.alchemyapi.io/v2/your-api-key"
NODE_CHAIN_ID=1
 
# Block monitor config
SLEEP_INTERVAL=100
MAX_BLOCKS_PER_QUERY=10
 
# Database config
SQL_DB="my_indexer_db"     # PostgreSQL database name
SQL_USERNAME="postgres"    # Database username
SQL_PASSWORD="password"    # Database password
SQL_HOST="localhost"       # Database host
SQL_PORT=5432             # Database port

Using the Configuration

In your application's main module:

import { Module } from '@nestjs/common';
import { IndexerModule } from '@open-ethereum/indexer';
import { indexerConfig } from './indexer.config';
 
@Module({
  imports: [IndexerModule.forRoot(indexerConfig)],
})
export class AppModule {}

Common Configuration Patterns

Disabling Features

const indexerConfig: IndexerConfig = {
  // ... other config
  app: {
    disableRootController: true, // Disable main API endpoints
    disableBlockMonitorController: true, // Disable block monitor endpoints
    disableMetrics: true, // Disable Prometheus metrics
    disablePino: true, // Disable Pino logging
  },
};

Contract Event Filtering

const indexerConfig: IndexerConfig = {
  indexer: {
    contracts: {
      MyContract: {
        abi: ContractABI,
        address: '0x123...',
        excludeEvents: ['Approval', 'AdminChanged'], // Events to ignore
      },
    },
  },
};

Wildcard Event Matching

const indexerConfig: IndexerConfig = {
  indexer: {
    contracts: {
      ERC20: {
        abi: [
          'event Transfer(address indexed from, address indexed to, uint256 value)',
        ],
        startBlock: 1234567,
        // No address specified = match all contracts
      },
    },
  },
};