Client for interacting with The Graph Networks Registry. Provides methods to load the registry from json, file or URL.

Constructors

Accessors

  • get networks(): Network[]
  • Gets all networks in the registry.

    Returns Network[]

    Array of all network elements

  • get updatedAt(): Date
  • Gets the date of the last update of the registry.

    Returns Date

    Date object

  • get version(): string
  • Gets the version of the loaded registry.

    Returns string

    Version string

Methods

  • Gets API URLs for a network, filtered by kind and with environment variables applied. Environment variable placeholders in the format {VARIABLE_NAME} will be replaced with actual environment variable values. URLs that reference non-existent environment variables will be omitted from the result.

    Parameters

    • networkId: string

      The network ID or alias

    • kinds: APIURLKind[] = []

      Optional array of API URL kinds to filter by. If not provided or empty, returns all kinds

    Returns string[]

    Array of API URLs with environment variables applied

    // Get all Etherscan API URLs
    const etherscanUrls = registry.getApiUrls("mainnet", [APIURLKind.Etherscan]);

    // Get all API URLs for the network
    const allUrls = registry.getApiUrls("mainnet");
  • Finds a network by its ID or one of its aliases.

    Parameters

    • alias: string

      The network ID or alias (e.g. "eth" for Ethereum mainnet)

    Returns undefined | Network

    The network if found, undefined otherwise

    const ethereum = registry.getNetworkByAlias("eth");
    
  • Finds a network by its unique identifier.

    Parameters

    • id: string

      The network ID (e.g. "mainnet", "optimism")

    Returns undefined | Network

    The network if found, undefined otherwise

    const mainnet = registry.getNetworkById("mainnet");
    
  • Gets RPC URLs for a network with environment variables applied. Environment variable placeholders in the format {VARIABLE_NAME} will be replaced with actual environment variable values. URLs that reference non-existent environment variables will be omitted from the result.

    Parameters

    • networkId: string

      The network ID or alias

    Returns string[]

    Array of RPC URLs with environment variables applied

    // Get all RPC URLs for ethereum mainnet
    const rpcUrls = registry.getRpcUrls("mainnet");
  • Fetches and loads a specific version of the networks registry. First tries to fetch from the primary registry URL at registry.thegraph.com, then falls back to the fallback URL at GitHub

    Parameters

    • version: string

      The exact version to fetch (e.g. "0.5.0")

    Returns Promise<NetworksRegistry>

    Promise that resolves to a new NetworksRegistry instance

    Error if the registry fetch fails

    const registry = await NetworksRegistry.fromExactVersion("0.5.0");
    
  • Loads the networks registry from a local JSON file.

    Parameters

    • path: string

      Path to the JSON file

    Returns NetworksRegistry

    A new NetworksRegistry instance

    Error if the file cannot be read or contains invalid data

  • Creates a new registry instance from a JSON string.

    Parameters

    • json: string

      The JSON string containing registry data

    Returns NetworksRegistry

    A new NetworksRegistry instance

    Error if the JSON is invalid

  • Fetches and loads the latest version of the networks registry. First tries to fetch from the primary registry URL at registry.thegraph.com, then falls back to the fallback URL at GitHub Uses the library version to determine the latest compatible registry URL. Library version 0.5.x will use the latest registry version 0.5.y even if 0.6.z is available

    Returns Promise<NetworksRegistry>

    Promise that resolves to a new NetworksRegistry instance

    Error if the registry fetch fails

    const registry = await NetworksRegistry.fromLatestVersion();
    
  • Loads the networks registry from a URL.

    Parameters

    • url: string

      The URL to fetch the registry from

    Returns Promise<NetworksRegistry>

    Promise that resolves to a new NetworksRegistry instance

    Error if the fetch fails or the response is invalid

  • Gets the URL for a specific version of the registry at GitHub.

    Parameters

    • version: string

      The exact version (e.g. "0.5.0")

    Returns string

    The URL string for the specified version

  • Gets the URL for a specific version of the registry.

    Parameters

    • version: string

      The exact version (e.g. "0.5.0")

    Returns string

    The URL string for the specified version

  • Gets the URL for the latest compatible version of the registry at GitHub. Uses the major and minor version from package.json.

    Returns string

    The URL string for the latest version

  • Gets the URL for the latest compatible version of the registry. Uses the major and minor version from package.json.

    Returns string

    The URL string for the latest version