# ethereum-event-processor

> Ethereum Event Processor

Latest version **5.1.2** (published 2021-12-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install ethereum-event-processor
pnpm add ethereum-event-processor
yarn add ethereum-event-processor
bun add ethereum-event-processor
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.1.2 |
| Published | 2021-12-02 |
| First published | 2019-02-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Santiago Carullo |
| Maintainers | santac89 |
| Keywords | ethereum, solidity, blockchain, event, listener, web3js |

## Links

- npm: https://www.npmjs.com/package/ethereum-event-processor
- Repository: https://github.com/santiac89/ethereum-event-processor
- Homepage: https://github.com/santiac89/ethereum-event-processor#readme
- Issues: https://github.com/santiac89/ethereum-event-processor/issues
- npm.io page: https://npm.io/package/ethereum-event-processor

## Dependencies (2)

- [web3](https://npm.io/package/web3.md) ^1.5.2
- [debug](https://npm.io/package/debug.md) ^3.1.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 5.1.2 (latest) — 2021-12-02
- 5.1.1 — 2021-12-01
- 5.1.0 — 2021-12-01
- 5.0.0 — 2021-12-01
- 4.0.1 — 2019-05-26
- 4.0.0 — 2019-05-26
- 3.0.0 — 2019-04-01
- 2.0.2 — 2019-03-31
- 2.0.1 — 2019-03-31
- 1.0.2 — 2019-03-30
- 1.0.1 — 2019-02-13
- 1.0.0 — 2019-02-13

## README

# ethereum-event-processor

## Description

This module is intended to listen for events that takes place in Ethereum blockchain and act accordingly.

Basically, it polls events from the provided contracts every X milliseconds and executes the corresponding callback for that event passing the event information to it.

## Usage

  ```
  const EthereumEventProcessor = require('ethereum-event-processor');
  const Web3 = require('web3');
  const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));

  const options = { pollingInterval: 500, startBlock: 200, blocksToWait: 20, blocksToRead: 20 };
    
  const eventProcessor = new EthereumEventProcessor(web3, contract.address, contract.abi, options);

  eventProcessor.on('EventName', (event) => {
    console.log(fromBlock, lastBlock); 
  });

  eventProcessor.on('blocks_processed', (fromBlock, lastBlock) => {
    console.log(fromBlock, lastBlock); 
  });

  eventProcessor.listen();
  eventProcessor.stop();
  ```

## **EthereumEventProcessor**

### `constructor(web3, contract_address, contract_abi options)`

Arguments:

### ***web3*** 

A Web3 connection object to the blokchain.

### ***contract_address***

The address of the contract to listen for events.

### ***contract_abi***

The ABI in JSON format of the contract to listen for events.

### ***options***

A JavaScript object containing the configuration for the event processor behaviour.

***startBlock***  Block number to start listening from.

***pollingInterval*** Interval in milliseconds between every poll to the blockchain.

***blocksToWait*** Number of blocks to wait before start reading events from new blocks. This will make the interval to be skipped if `(latestBlockNumber - lastReadBlock + blocksToRead) < blocksToWait`.

***blocksToRead*** Number of blocks to read in each interval.

### `listen(options)`

Starts or resumes the events processor consuming process. It can receive the same arguments as the constructor options to override default behaviour.

### `stop`

Stop the current event processor consuming process.

### `on('end', function(fromBlock, toBlock))`

Receives a function to be executed every time a new set of blocks is processed. The function receives the start and end numbers of the blocks that have been processed in that iteration.

### `on(eventName, function(event))`

Receives a function to be executed every time the event specified as a string with `eventName` has been received. The function receives the event object as an argument.

---
_Source: https://npm.io/package/ethereum-event-processor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
