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

  • 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");
    
  • Fetches and loads a specific version of the networks registry.

    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. 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.

    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. Uses the major and minor version from package.json.

    Returns string

    The URL string for the latest version