# sc-indexer

> A super fast, low level events indexer for smart contracts on Ethereum. This package allows for efficient indexing and querying of events emitted by smart contracts on the Ethereum blockchain.

Latest version **0.0.52** (published 2023-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install sc-indexer
pnpm add sc-indexer
yarn add sc-indexer
bun add sc-indexer
```

## 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.0.52 |
| Published | 2023-01-29 |
| First published | 2023-01-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 52.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Aziz Aiden |
| Maintainers | azizaiden |
| Keywords | ethereum, smartcontract, contract, sc, indexer, indexing |

## Links

- npm: https://www.npmjs.com/package/sc-indexer
- Repository: https://github.com/azizaiden/sc-indexer
- Homepage: https://github.com/azizaiden/sc-indexer#readme
- Issues: https://github.com/azizaiden/sc-indexer/issues
- npm.io page: https://npm.io/package/sc-indexer

## Dependencies (6)

- [web3](https://npm.io/package/web3.md) ^1.8.1
- [mongodb](https://npm.io/package/mongodb.md) ^3.0.2
- [winston](https://npm.io/package/winston.md) 3.0.0-rc0
- [bottleneck](https://npm.io/package/bottleneck.md) ^2.19.5
- [abi-decoder](https://npm.io/package/abi-decoder.md) ^2.4.0
- [bignumber.js](https://npm.io/package/bignumber.js.md) ^5.0.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.52 (latest) — 2023-01-29
- 0.0.51 — 2023-01-29
- 0.0.5 — 2023-01-29
- 0.0.4 — 2023-01-29
- 0.0.32 — 2023-01-27
- 0.0.31 — 2023-01-27
- 0.0.3 — 2023-01-27
- 0.0.2 — 2023-01-27
- 1.0.0 — 2023-01-27

## README

# SC Indexer

A fast and low-level Ethereum indexer that can be used to index Ethereum events from a smart contract and store them into different types of databases. It supports File System and MongoDB as a database at the moment.


## Features

- Supports file-based and MongoDB-based storage
- Supports limiting the rate at which events are indexed
- Uses Bottleneck library for rate limiting and handling the load on Ethereum nodes.
- Implements both real-time and batch-based indexing
- Provides a detailed log of events while indexing the events.

## Prerequisites

You need to have Node.js and npm installed.


### Installation

Install sc-indexer with npm

```bash
  npm install sc-indexer
```
    
## Usage/Examples
The `Indexer` class can be instantiated with the following parameters:

- `store (required)`: the store to be used for indexing events
- `abi (required)`: the ABI of the smart contract
- `contractAddress (required)`: the address of the smart contract
- `events (required)`: an object mapping event names and the corresponding keys
- `readProviderUrl (optional)`: the URL of the Ethereum JSON-RPC endpoint to use for reading events (defaults to http://127.0.0.1:8545)
After instantiating the `Indexer`, events can be synced with the `syncAll` method. This method takes the following parameters:

- `fromBlock (required)`: the starting block number for syncing events
- `toBlockNum (optional)`: the ending block number for syncing events (defaults to the current block number)
- `chunkSize (optional)`: the number of events to process in a single batch (defaults to 200) (depends on RPC provider limit)
- `live (optional)`: a boolean indicating whether to sync events in real-time (defaults to false)

```javascript
import { Indexer, stores } from 'sc-indexer'

const abi = [ ... ]
const contractAddress = '0x...'
const events = { events: {
                    Event_name: {
                        keys: ['value1', 'value2', ..]
                      }
                    }           
                  }

const newStore = new stores.Mongodb(events, 'mongodb_url')
const indexer = new Indexer(newStore, abi, contractAddress, events.events, readProviderUrl)
await indexer.syncAll({ fromBlock: 0, live: true })
```


## Contributing

Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.



## License

[MIT](https://choosealicense.com/licenses/mit/)

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