🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@drizzle-utils/new-block-stream

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@drizzle-utils/new-block-stream

A tool for creating a stream of new block data.

0.3.0-alpha.0
latest
npm
Version published
Maintainers
4
Created
Source

@drizzle-utils/new-block-stream

A tool for creating a stream of new block data.

Usage

Getting started

Install via npm:

npm install @drizzle-utils/new-block-stream

Usage example (taken from @drizzle-utils/new-block-stream/example.js)

const Web3 = require("web3");
const createNewBlock$ = require("@drizzle-utils/new-block-stream");

const web3 = new Web3("ws://127.0.0.1:9545");

const { observable, cleanup } = createNewBlock$({
  web3,
  pollingInterval: 200, // only used if non-WebsocketProvider
});

// log out new blocks
observable.subscribe(block => console.log(block));

// stop listening to new blocks and end the stream
cleanup();

Note that listening to new blocks might skip blocks if polling is being used and the pollingInterval is longer than the rate in which new blocks are being produced.

API

createNewBlock$

Creates an RxJS observable that will monitor the blockchain for new blocks. Supports both Web3 subscriptions and polling.

Parameters

options - Object

  • web3 - Object: A Web3 instance
  • pollingInterval (only used for non-WebsocketProvider) - Number: The rate in milliseconds at which the stream should poll for new blocks.

Returns

Object

  • observable: An RxJS observable.
  • cleanup: A function for cleaning up listeners and completing/ending the streams created.
  • subscription: This is only returned if the provider passed-in is a WebsocketProvider. This is a reference to the underlying Web3 subscription object.

FAQs

Package last updated on 16 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts