Skip to content

A super fast, low level events indexer for smart contracts on Ethereum.

License

Notifications You must be signed in to change notification settings

0xaaiden/sc-indexer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SC Indexer

Node version

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-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)

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

About

A super fast, low level events indexer for smart contracts on Ethereum.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published