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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@omnihash/nestjs-evm-events

v1.1.1

Published

A NestJS module for robust Ethereum event listening and contract interaction using ethers.js

Readme

@omnihash/nestjs-evm-events

A NestJS module for robust Ethereum event listening.


Installation

npm install @omnihash/nestjs-evm-events ethers
# or
yarn add @omnihash/nestjs-evm-events ethers

Usage

1. Configure Environment

Create a .env file in your project root:

EVM_RPC_PROVIDER_URL=https://eth-mainnet.g.alchemy.com/v2/your-api-key
EVM_MAX_RECONNECT_ATTEMPTS=10
EVM_RECONNECT_DELAY=5000
EVM_HEARTBEAT_INTERVAL=30000
EVM_POLLING_INTERVAL=4000
EVM_KEEP_ALIVE_INTERVAL=15000
EVM_RECONNECTION_INTERVAL=1800000

Configuration Options:

| Environment Variable | Description | Default | | ---------------------------- | ---------------------------------------- | ---------- | | EVM_RPC_PROVIDER_URL | WebSocket or HTTP RPC URL | required | | EVM_MAX_RECONNECT_ATTEMPTS | Max attempts for reconnection | 10 | | EVM_RECONNECT_DELAY | Delay between reconnection attempts (ms) | 5000 | | EVM_HEARTBEAT_INTERVAL | Interval to check connection health (ms) | 30000 | | EVM_POLLING_INTERVAL | Polling interval for HTTP providers (ms) | 4000 | | EVM_KEEP_ALIVE_INTERVAL | Interval to send keep-alive pings (ms) | 15000 | | EVM_RECONNECTION_INTERVAL | Interval for periodic reconnection (ms) | 1800000 |


2. Example Usage

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { EvmEventsModule, EvmEventsService } from '@omnihash/nestjs-evm-events';
import { AppController } from './app.controller';
import { AppService } from './app.service';

const ERC20_ADDRESS = '0x6982508145454Ce325dDbE47a25d4ec3d2311933';
const ERC20_ABI = [
  'event Transfer(address indexed from, address indexed to, uint256 value)',
];

@Module({
  imports: [EvmEventsModule, ConfigModule],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {
  constructor(private readonly evmEventsService: EvmEventsService) {
    void this.run();
  }

  async run() {
    await this.evmEventsService.registerContract(
      ERC20_ADDRESS,
      ERC20_ABI,
      (event) => {
        // Do stuff here
        console.log('Event received:', event);
      },
    );
  }
}

API

EthersModule

  • EvmEventsModule
    Loads configuration from .env and sets up the listener service.

EthersListenerService

  • registerContract(address: string, abi: ethers.InterfaceAbi, callback?: (event) => void): void
    Register a contract to listen for all its events.
  • registerSpecificEvents(address: string, abi: ethers.InterfaceAbi, eventNames: string[], callback?: (event) => void): void
    Register specific events from a contract.
  • getEventsInBlockRange(address: string, abi: ethers.InterfaceAbi, eventNameOrFragment: ethers.ContractEventName, startBlock: number, endBlock: number, increment = 1000): Promise<ethers.EventLog[]>
    Fetch all events for a contract in a block range with automatic batching.

Example: Fetching Historical Events

import { Injectable } from '@nestjs/common';
import { EvmEventsService } from '@omnihash/nestjs-evm-events';

@Injectable()
export class YourService {
  constructor(private readonly evmEventsService: EvmEventsService) {}

  async fetchTransferEvents() {
    const ERC20_ADDRESS = '0x6982508145454Ce325dDbE47a25d4ec3d2311933';
    const ERC20_ABI = [
      'event Transfer(address indexed from, address indexed to, uint256 value)',
    ];

    // Fetch all Transfer events from the last 1000 blocks
    const currentBlock = await yourRpcProvider.getBlockNumber();
    const events = await this.evmEventsService.getEventsInBlockRange(
      ERC20_ADDRESS,
      ERC20_ABI,
      '*', // '*' for all events or event name
      currentBlock - 1000, // start block
      currentBlock, // end block
      100, // batch size (optional)
    );

    for (const event of events) {
      console.log('Event:', event);
    }
  }
}

License

MIT