sc-indexer
v0.0.52
Published
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.
Downloads
22
Maintainers
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
npm install sc-indexerUsage/Examples
The Indexer class can be instantiated with the following parameters:
store (required): the store to be used for indexing eventsabi (required): the ABI of the smart contractcontractAddress (required): the address of the smart contractevents (required): an object mapping event names and the corresponding keysreadProviderUrl (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 eventstoBlockNum (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
Contributing Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
