# eth-history

> Utility for retrieving historical block/event data for contract address

Latest version **0.1.6** (published 2019-10-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install eth-history
pnpm add eth-history
yarn add eth-history
bun add eth-history
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2019-10-08 |
| First published | 2019-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 51.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | TekHedz, LLC |
| Maintainers | mdcoon |
| Keywords | ethereum, blockchain, events, tracking |

## Links

- npm: https://www.npmjs.com/package/eth-history
- Repository: https://github.com/buidlhub/eth-history
- Homepage: https://github.com/buidlhub/eth-history#readme
- Issues: https://github.com/buidlhub/eth-history/issues
- npm.io page: https://npm.io/package/eth-history

## Dependencies (3)

- [yup](https://npm.io/package/yup.md) ^0.27.0
- [debug](https://npm.io/package/debug.md) ^4.1.1
- [eth-sync](https://npm.io/package/eth-sync.md) ^0.1.10

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.1.6 (latest) — 2019-10-08
- 0.1.5 — 2019-10-08
- 0.1.4 — 2019-10-02
- 0.1.3 — 2019-10-02
- 0.1.2 — 2019-10-02
- 0.1.1 — 2019-10-02
- 0.1.0 — 2019-08-14

## README

# eth-history
Utility for retrieving/replaying historical blocks/events for a specific contract address.

# Motivation
Sometimes it's good to have a simple utility that recovers historical block and/or event data in a robust way. This utility will retrieve all blocks/events in the requested range and make retries upon failure or empty results. This is useful when using Infura or other managed RPC platform where failures and/or timeouts are common.

# Installation
npm install eth-history

# Usage
```javascript
let hist = new ETHHistory({
    web3: <web3-instance>,
    targetAddress: <contract_address>,
    abi: <abi array>
});

let cb = async (e, block) => {
   //log error or handle recovered block
}

//upon completion, callback should have been given all recovered blocks
await hist.recoverBlocks({
   fromBlock: <starting block number>,
   toBlock: <end block number>
}, cb);

//we could also get historical events
let evtHandler = (e, txns) => {
   //txns will be a bundle of information for each matching block where events were found. The txns will be 
   //contained in a 'logEvents' map where each event name maps to an array of event metadata.
}

//this will retrieve all events in the given block range, regardless of how many events are available. 
//It uses eth-sync utility to incrementally retrieve block ranges until all events retrieved 
//(i.e. it works around Infura limits if using Infura as an RPC provider).
await hist.recoverEvents({
    fromBlock: <start block>,
    toBlock: <end block>
}, evtHandler);
```

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