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.
- 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.
You need to have Node.js and npm installed.
Install sc-indexer with npm
npm install sc-indexerThe 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 theIndexer, events can be synced with thesyncAllmethod. 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)
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 Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.