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

@xdapps/ethers-event-listeners-lib

v1.0.8

Published

Basic event listener library for ERC-20, ERC-721, and ERC-1155 Transfer events using Ethers.js

Downloads

12

Readme

Ethereum Event Listeners for ERC-20, ERC-721, & ERC-1155 transfer events

This is a basic wrapper around Ethers.js with static methods for listening to transfer events on ERC-20, ERC-721, or ERC-1155 contracts. This was created as a basic example to demonstrate how to listen to events and take action in real time.

Basics

  1. Import the protocol you want to interact with.
  2. Instantiate listeners with an array of contract address and an Ethers provider.
  3. Start the listeners and pass in a callback function to be executed upon each transfer event found.

How To Use

npm install @xdapps/ethers-event-listeners-lib
or
yarn add @xdapps/ethers-event-listeners-lib
import {ERC20TransferListeners, ERC20TransferEvent} from "@xdapps/ethers-event-listeners-lib";

const listOfERC20Contracts = ["0x.....", "0x...."]; // List of contracts to listen to
const provider = new ethers.providers.JsonRpcProvider("RPC_URL_ADDRESS");

const callBackForTransferEvent = (eventData: ERC20TransferEvent){
// Your code to handle the transfer event goes here.....
//......
//......
}
const listeners = ERC20TransferListeners.getInstance(listOfERC20Contracts, provider);
await listeners.start(callBackForTransferEvent);

Poll for Redundancy

Sometimes, the real time listeners can miss events, it's not common, but for redundancy, I've built back up "pollers" that allow you to go behind the listeners and poll specific block ranges for specific events.

I prefer to have the real time listeners running and then poll every 3-5 minutes to ensure no events are missed.

import {ERC20TransferPoller, ERC20TransferEvent} from "@xdapps/ethers-event-listeners-lib";

const contractToPoll = "0x....."; // Address of contract to poll
const provider = new ethers.providers.JsonRpcProvider("RPC_URL_ADDRESS");
const lastBlockPolled = 10000;
const maxBlocksPerPoll = 500;

const callBackForTransferEvent = (eventData: ERC20TransferEvent){
// Your code to handle the transfer event goes here.....
//......
//......
}
const poller = new ERC20TransferPoller(contractToPoll, lastBlockPolled, maxBlocksPerPoll);
await poller.pollBlocks(provider, callBackForTransferEvent);