Honeycomb

HealthChecker

Monitor, score, and switch between Hive API endpoints with a full UI for managing providers.

Svelte: Programmatic API Only

The HealthChecker UI component is available for React and Vue. Svelte provides programmatic access via HealthCheckerService and createDefaultCheckers.

Zero-Config Defaults

When HiveProvider has no healthCheckerServices prop, a default service is created automatically with the key "default". It uses DEFAULT_API_ENDPOINTS and runs basic database checks, so you can use HealthCheckerComponent without any configuration.

Features

  • Score-based endpoint ranking with latency measurement
  • Automatic and manual switching to the best provider
  • Add, remove, and reset custom API endpoints
  • Validation error reporting with detailed diagnostics
  • Confirmation dialog before switching to unverified nodes
  • Provider list persisted in localStorage across sessions
  • Multiple independent instances per application

Basic Usage

The simplest setup requires no configuration. A default health checker service is created automatically with basic database API checks against the default endpoints.

import { HiveProvider, HealthCheckerComponent } from "@hiveio/honeycomb-react";

function App() {
  return (
    <HiveProvider>
      <HealthCheckerComponent healthcheckerKey="default" />
    </HiveProvider>
  );
}

Custom Configuration

For full control, pass healthCheckerServices to HiveProvider. Each service defines its own endpoints, API checks, and node-change callback.

import {
  HiveProvider,
  HealthCheckerComponent,
  type HealthCheckerServiceConfig,
} from "@hiveio/honeycomb-react";

const ENDPOINTS = [
  "https://api.hive.blog",
  "https://api.openhive.network",
  "https://api.syncad.com",
  "https://anyx.io",
  "https://techcoderx.com",
  "https://api.deathwing.me",
];

const healthCheckerServices: HealthCheckerServiceConfig[] = [
  {
    key: "my-api",
    defaultProviders: ENDPOINTS,
    nodeAddress: null,
    onNodeChange: (node, chain) => {
      if (node) {
        chain.endpointUrl = node;
      }
    },
    createCheckers: (chain) => [
      {
        title: "Database - Find accounts",
        method: chain.api.database_api.find_accounts,
        params: { accounts: ["hiveio"], delayed_votes_active: false },
        validatorFunction: (data: unknown) =>
          data?.accounts?.[0]?.name === "hiveio"
            ? true
            : "Find accounts error",
      },
      {
        title: "Database - Dynamic global properties",
        method: chain.api.database_api.get_dynamic_global_properties,
        params: {},
        validatorFunction: (data: unknown) =>
          !!data?.head_block_number
            ? true
            : "Dynamic global properties error",
      },
    ],
  },
];

function App() {
  return (
    <HiveProvider healthCheckerServices={healthCheckerServices}>
      <HealthCheckerComponent healthcheckerKey="my-api" />
    </HiveProvider>
  );
}

Multiple Instances

You can run multiple health checker services side by side, each monitoring different sets of endpoints with different checks. Use unique key values and render separate HealthCheckerComponent instances.

import {
  HiveProvider,
  HealthCheckerComponent,
  type HealthCheckerServiceConfig,
} from "@hiveio/honeycomb-react";

const NODE_ENDPOINTS = [
  "https://api.hive.blog",
  "https://api.openhive.network",
  "https://anyx.io",
  "https://techcoderx.com",
];

const WALLET_ENDPOINTS = [
  "https://api.hive.blog",
  "https://api.openhive.network",
  "https://api.deathwing.me",
];

const healthCheckerServices: HealthCheckerServiceConfig[] = [
  {
    key: "hive-node-api",
    defaultProviders: NODE_ENDPOINTS,
    nodeAddress: null,
    onNodeChange: (node, chain) => {
      if (node) chain.endpointUrl = node;
    },
    createCheckers: (chain) => {
      const api = chain.api as any;
      return [
        {
          title: "Database - Find accounts",
          method: chain.api.database_api.find_accounts,
          params: { accounts: ["hiveio"], delayed_votes_active: false },
          validatorFunction: (data: unknown) =>
            data?.accounts?.[0]?.name === "hiveio" ? true : "Error",
        },
        {
          title: "Bridge - Get Ranked Posts",
          method: api.bridge.get_ranked_posts,
          params: { observer: "hive.blog", tag: "", limit: 10, sort: "trending" },
          validatorFunction: (data: unknown) =>
            data?.length > 0 ? true : "Bridge API error",
        },
      ];
    },
  },
  {
    key: "hive-wallet-api",
    defaultProviders: WALLET_ENDPOINTS,
    nodeAddress: null,
    onNodeChange: (node, chain) => {
      if (node) chain.endpointUrl = node;
    },
    createCheckers: (chain) => [
      {
        title: "Database - Dynamic global properties",
        method: chain.api.database_api.get_dynamic_global_properties,
        params: {},
        validatorFunction: (data: unknown) =>
          !!data?.head_block_number ? true : "Error",
      },
    ],
  },
];

function App() {
  return (
    <HiveProvider healthCheckerServices={healthCheckerServices}>
      <h2>Node API Health</h2>
      <HealthCheckerComponent healthcheckerKey="hive-node-api" />

      <h2>Wallet API Health</h2>
      <HealthCheckerComponent healthcheckerKey="hive-wallet-api" />
    </HiveProvider>
  );
}

HealthCheckerComponent Props

PropTypeRequiredDescription
healthcheckerKeystringYesKey matching a registered HealthCheckerServiceConfig.key. Use "default" for the auto-created service.

HealthCheckerServiceConfig

Each entry in the healthCheckerServices array configures one independent service instance.

PropertyTypeDescription
keystringUnique identifier for this service. Used as healthcheckerKey in the component.
createCheckers(chain) => ApiChecker[]Factory that receives the Hive chain instance and returns an array of API checks to run.
defaultProvidersstring[]Default list of API endpoint URLs to monitor. Users can add/remove providers at runtime.
nodeAddressstring | nullCurrently active node. Pass null to let the service pick one automatically.
onNodeChange(node, chain) => voidCalled when the service switches to a different node. Typically used to update chain.endpointUrl.
enableLogsbooleanEnable console logging for debugging health check results.

ApiChecker

Each checker defines a single API call that is executed against every provider during health checks.

PropertyTypeDescription
titlestringDisplay name shown in the UI for this check.
methodanyThe API method reference from chain.api (e.g. chain.api.database_api.find_accounts).
paramsanyParameters to pass to the API method.
validatorFunction(data) => true | stringReturns true if the response is valid, or an error message string.

Example checker

{
  title: "Database - Find accounts",
  method: chain.api.database_api.find_accounts,
  params: { accounts: ["hiveio"], delayed_votes_active: false },
  validatorFunction: (data: unknown) =>
    data?.accounts?.[0]?.name === "hiveio"
      ? true           // check passed
      : "Account not found"  // error message
}

Programmatic Access

Access the underlying HealthCheckerService instance via the useHive hook for programmatic control outside of the UI component.

import { useHive } from "@hiveio/honeycomb-react";

function MyComponent() {
  const { getHealthCheckerService } = useHive();
  const service = getHealthCheckerService("default");

  const handleStart = () => service?.startCheckingProcess();
  const handleStop = () => service?.stopCheckingProcess();
  const handleReset = () => service?.resetProviders();
  const handleAdd = () => service?.addProvider("https://my-node.example.com");
  const handleSwitch = () => service?.evaluateAndSwitch();

  return (
    <div>
      <button onClick={handleStart}>Start Checks</button>
      <button onClick={handleStop}>Stop Checks</button>
      <button onClick={handleSwitch}>Switch to Best</button>
      <button onClick={handleReset}>Reset Providers</button>
      <button onClick={handleAdd}>Add Custom Node</button>
    </div>
  );
}
MethodDescription
startCheckingProcess()Register all API checks and start automatic health monitoring.
stopCheckingProcess()Unregister all checks and stop monitoring.
evaluateAndSwitch()Run checks and switch to the highest-scoring provider.
addProvider(url)Add a custom endpoint URL to the provider list.
removeProvider(url)Remove an endpoint from the provider list.
resetProviders()Reset the provider list back to defaultProviders.
handleChangeOfNode(url)Manually switch the active node to a specific endpoint.

How It Works

Each HealthCheckerService uses the @hiveio/wax HealthChecker under the hood. It registers your API checks as endpoints, runs them against every provider, scores them by latency and success rate, and emits events that the HealthCheckerComponent listens to for live UI updates. Provider lists are persisted in localStorage so user customizations survive page reloads.

Default Checkers

The auto-created "default" service runs two checks: database_api.find_accounts (verifies account lookup) and database_api.get_dynamic_global_properties (verifies chain state). These work on any standard Hive API node. For advanced checks (Bridge API, witness lookups, etc.), provide a custom healthCheckerServices configuration.

API TrackerAvatar