Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xdapps/ethers-event-listeners-lib

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xdapps/ethers-event-listeners-lib

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

  • 1.0.7
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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);

Pollers 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);

FAQs

Package last updated on 12 Apr 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc