npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web3-event-manager

v1.0.8

Published

An event emitter class to provide callbacks when the web3 object changes

Downloads

8

Readme

A class that extends node.js events to create custom event listeners for apps relying on web3

github: https://github.com/Schwartz10/web3-event-manager

Configuration:

npm install web3-event-manager

Wherever you require web3-event-manager, create a new instance of the class:

import Web3Manager from 'web3-event-manager'
const web3EventManager = new Web3Manager()

When you want the web3EventManager to start listening for changes, run:

web3EventManager.start()

If you want the web3EventManager to stop listening for changes, run:

web3EventManager.stop()

Events to listen for:

Currently, the web3EventManager will fire callbacks, passing this data object when it hears change events. Further descriptions can be found below the table.

| Event | Data | |:------------|--------------| |web3Change | { data: { hasWeb3: bool, web3: web3Obj } } | |accountChange | { data: { unlockedAccount: bool, account: address or null } } | |networkChange | { data: { currentNetworkId: num, onCorrectNetwork: bool } } |

web3Change: web3EventManager.on('web3Change', callback)

Will fire the callback with a boolean if the user has a web3 object in their browser. The web3 object is accessible via the data object. To stop listening, call:

web3EventManager.removeListener('web3Change', callback)

accountChange: web3EventManager.on('accountChange', callback)

Will fire the callback with a boolean if the user has an unlocked ethereum account. The unlocked account's address is also provided in the data object. To stop listening, call:

web3EventManager.removeListener('accountChange', callback)

networkChange: web3EventManager.on('networkChange', callback)

Will fire the callback with a number representing the networkId of the network protocol the web3 object corresponds to. If the Web3EventManager was constructed with a required network (see Web3EventManager arguments), the data returned will provide a boolean if the user is on the required network (and true if no required network was provided). To stop listening, call:

web3EventManager.removeListener('networkChange', callback)

Instantiating the Web3Manager with arguments:

The Web3Manager currently takes 3 optional arguments: (1) interval (number) - instructs the Web3Manager to check for updates every (number) of milliseconds (2) requiredNetwork (number) - tells the Web3Manager that the user must be connected to a requiredNetwork (3) localProvider (string (localhost...)) - instructs the Web3Manager to construct the web3 object out of the localProvider, instead of the current provider injected into the browser by metamask, mist, or other related services.

If you wish to use these, simply call:

const Web3EventManager = new Web3Manager(interval, requiredNetwork, localProvider)