@hiveio/workerbee
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published

WorkerBee

Hive automation library based on the wax and beekeeper

Install

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 18 or higher is required.

Installation is done using the npm install command:

npm install @hive/workerbee

Usage

Iterating indefinitely over new blocks

import WorkerBee from "@hive/workerbee";

const bot = new WorkerBee();
bot.on("error", console.error);

await bot.start();

for await(const { block, number } of bot)
  console.info(`Got block #${block.block_id} (${number})`);

Wait for the next block using observer

import WorkerBee from "@hive/workerbee";

const bot = new WorkerBee();
bot.on("error", console.error);

await bot.start();

const block = await new Promise(blockResolve => {
  bot.once("block", blockResolve);
}); // Get one latest block

console.info(`Waiting for block: #${block.number + 1}`);
const observer = bot.observe.block(block.number + 1);

observer.subscribe({
  next() {
    console.info('Block detected');
  }
});

Observe given account for operations in blockchain

import WorkerBee from "@hive/workerbee";

const bot = new WorkerBee();
bot.on("error", console.error);

await bot.start();

const observer = bot.observe.accountOperations("gtg");

observer.subscribe({
  next(op) {
    console.info(op);
  }
});

Observe given account for full manabar regeneration

import WorkerBee from "@hive/workerbee";

const bot = new WorkerBee();
bot.on("error", console.error);

await bot.start();

const observer = bot.observe.accountFullManabar("gtg");

observer.subscribe({
  next(acc) {
    console.info(acc.voting_manabar); // { "current_mana": "0", "last_update_time": 0 }
  }
});

Broadcast and observe transaction in blockchain

import WorkerBee from "@hive/workerbee";
import beekeeperFactory from "@hive/beekeeper";

const beekeeper = await beekeeperFactory();
const session = await beekeeper.createSession("my.salt");
const { wallet } = await session.createWallet("w0", "mypassword");
await wallet.importKey("5JkFnXrLM2ap9t3AmAxBJvQHF7xSKtnTrCTginQCkhzU5S7ecPT");

const bot = new WorkerBee();
bot.on("error", console.error);

await bot.start();

// Build transaction
const builder = await bot.chain.getTransactionBuilder();
builder.push({
  vote: {
    voter: "otom",
    author: "c0ff33a",
    permlink: "ewxhnjbj",
    weight: 2200
  }
});

// Broadcast our transaction with custom internal expiration time
const observer = await bot.broadcast(builder.build(wallet, "5RqVBAVNp5ufMCetQtvLGLJo7unX9nyCBMMrTXRWQ9i1Zzzizh"));

// Observe if our transaction has been applied
observer.subscribe({
  next(tx) {
    console.info(tx, "applied in blockchain");
  },
  error() {
    console.error("Transaction observation time expired");
  }
});

API

See API definition in api.md

Support and tests

Tested on the latest Chromium (v117) and Node.js v18.7.0

Automated CI test runs are available.

To run the tests on your own, clone the Wax repo and install the dependencies and then compile the project:

sudo npm install -g pnpm
pnpm install

Compile source:

npm run build

Then run tests:

npm run test

License

See license in the LICENSE.md file

Readme

Keywords

none

Package Sidebar

Install

npm i @hiveio/workerbee

Weekly Downloads

1

Version

0.4.1

License

SEE LICENSE IN LICENSE.md

Unpacked Size

60.3 kB

Total Files

7

Last publish

Collaborators

  • mtyszczak
  • thebeedevs
  • mahdiyari
  • therealwolf
  • bgornicki
  • openhive
  • feruzm