Hive Developer Portal
Workerbee subscribe and filter
Subscribe to posts, comments, votes, custom_json, and combined account/type filters.
Subscribe to live Hive activity with Workerbee observers: posts, comments, votes, custom JSON, and combined filters. Assumes you already installed and started a bot.
Full category tree: predefined_filter_categories.md. Stack guidance: Building agents · SDK Reference · llms.txt.
Setup (reminder)
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();
Filter by account and content type
// New posts by one or more authors
bot.observe.onPosts("gtg", "blocktrades").subscribe({
next(data) {
for (const account of Object.keys(data.posts)) {
for (const { operation } of data.posts[account] ?? []) {
console.log(`Post @${operation.author}/${operation.permlink}`);
}
}
},
error: console.error
});
// Comments
bot.observe.onComments("gtg").subscribe({
next(data) {
console.log("comment event", data);
},
error: console.error
});
// Votes involving accounts
bot.observe.onVotes("gtg").subscribe({
next(data) {
console.log("vote event", data);
},
error: console.error
});
// Application custom_json by id (agent / game payloads)
bot.observe.onCustomOperation("follow").subscribe({
next(data) {
for (const { operation } of data.customOperations["follow"] ?? []) {
console.log("custom_json follow", operation);
}
},
error: console.error
});
Combine filters (implicit OR, explicit .or / .and)
Chained observers default to OR (fire when any condition matches; duplicates in one cycle are coalesced):
bot.observe
.onImpactedAccounts("alice", "bob")
.onPosts("gtg")
.subscribe({
next(data) {
console.log("account activity and/or gtg post", data);
},
error: console.error
});
Require all conditions with .and (AND binds tighter than OR):
import { EManabarType } from "@hiveio/wax";
bot.observe
.onAccountsFullManabar(EManabarType.RC, "initminer")
.and
.onNewAccount()
.subscribe({
next(data) {
console.log("full RC and a new account in the same cycle", data);
},
error: console.error
});
Historical then live
providePastOperations backfills a block range (or relative time like '-7d'), then you can keep the same observer style for live data:
bot.providePastOperations(96_549_390, 96_549_415)
.onPosts("gtg")
.subscribe({
next(data) {
console.log("historical posts", data);
},
error: console.error,
complete() {
console.log("backfill complete");
}
});
Unsubscribe
const sub = bot.observe.onBlock().subscribe({ next() { /* ... */ }, error: console.error });
// later:
sub.unsubscribe();
Related
- Getting started
- Errors and reconnect
- Legacy DHive streaming contrast: Streaming blockchain transactions