0.2.1 • Published 2 years ago

@hive-staging/autobee v0.2.1

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
gitlab
Last release
2 years ago

AutoBee

Example bot to use in your browser app based on the wax and beekeeper library

Install

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

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

Installation is done using the npm install command:

npm install @hive-staging/autobee

Usage

Iterating indefinitely over new blocks

import AutoBee from "@hive-staging/autobee";

const bot = new AutoBee({ postingKey: '5JkFnXrLM2ap9t3AmAxBJvQHF7xSKtnTrCTginQCkhzU5S7ecPT' });
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 AutoBee from "@hive-staging/autobee";

const bot = new AutoBee({ postingKey: '5JkFnXrLM2ap9t3AmAxBJvQHF7xSKtnTrCTginQCkhzU5S7ecPT' });
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);

const observed = observer.subscribe({
  next() {
    console.info('Block detected');
  },
  // Complete method is optional
  complete() {
    observed.unsubscribe();
  }
});

API

See API definition in api.md

Support and tests

Tested on the latest Chromium (v117)

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