Hive Developers logo

Hive Developer Portal

Workerbee getting started

Install @hiveio/workerbee, connect with WAX, and stream live Hive blocks.

Install @hiveio/workerbee, connect through WAX, and stream live blocks. Prefer this stack for new automation and agent work over legacy DHive streaming patterns.

Canonical upstream: Workerbee README · high-level docs · filter categories. Portal context: Building agents, SDK Reference, Tools, llms.txt.

Requirements

npm install @hiveio/workerbee @hiveio/wax

Point reads at a public HTTPS node (see Hive Nodes). Examples below use https://api.hive.blog/.

Create a chain and start the bot

Current @hiveio/workerbee constructs with a WAX chain interface (not a no-arg constructor):

import { createHiveChain } from "@hiveio/wax";
import WorkerBee from "@hiveio/workerbee";

const chain = await createHiveChain({
  apiEndpoint: "https://api.hive.blog/"
});

const bot = new WorkerBee(chain);
bot.start();

console.log("Workerbee running:", bot.running, "version:", bot.getVersion());

start() begins the live notify loop. Call bot.stop() to pause and bot.delete() when tearing down (also releases the managed WAX/Beekeeper objects when Workerbee owns them).

Stream every new block

The bot is an async iterator over live block headers (errors are ignored on the default iterator):

for await (const { id, number, timestamp, witness } of bot) {
  console.log(`Block #${number} ${id} @ ${timestamp.toISOString()} by ${witness}`);
}

Equivalent observer form:

bot.observe.onBlock().subscribe({
  next(data) {
    console.log(`Block #${data.block.number}`);
  },
  error: console.error
});

First account observer

Listen for activity that impacts a specific account:

bot.observe.onImpactedAccounts("gtg").subscribe({
  next(data) {
    for (const { transaction } of data.impactedAccounts["gtg"] ?? []) {
      console.log(`Impacted tx ${transaction.id}`);
    }
  },
  error: console.error
});

Next steps