Streaming

The library can follow the chain in real time by polling dynamic global properties. Each stream method returns a release function — call it to stop streaming.

All four accept an optional mode of 'head' (default) or 'irreversible'.

streamBlockNumber

Fires for each new block number.

const release = steem.api.streamBlockNumber((err, blockNum) => {
  console.log(blockNum);
});

// later
release();

You can also tune the poll interval (ms): streamBlockNumber(mode, callback, ts).

streamBlock

Fires with each full block object.

const release = steem.api.streamBlock((err, block) => {
  console.log(block);
});

streamTransactions

Fires once per transaction within each block.

const release = steem.api.streamTransactions('head', (err, tx) => {
  console.log(tx);
});

streamOperations

Fires once per operation — the most granular stream.

const release = steem.api.streamOperations('head', (err, operation) => {
  const [opName, opPayload] = operation;
  if (opName === 'vote') console.log('vote', opPayload);
});

Choosing a mode

  • 'head' — newest blocks, may still be reversed by a fork.
  • 'irreversible' — only blocks confirmed by enough witnesses; lags head but is final.

This site uses Just the Docs, a documentation theme for Jekyll.