ei
eth-indexer
npm i eth-indexer
ei

eth-indexer

High performance Ethereum smart contract event indexing for fast local retrieval

by Dominiek Ter Heide

0.1.12 (see all)License:MITTypeScript:Not Found
npm i eth-indexer
Readme

High Performance Ethereum Indexer

Syncs events from Ethereum and indexes them for fast retrieval. This is useful and often essential for production Dapps.

  • Support for 6 different persistence stores
  • Includes "single-node friendly" stores such as flat-file JSON
  • Comprehensive error retry logic when communicating with Ethereum node
  • Maximum throughput via JSON RPC using batched parallel fetching

Todo

  • Keep track of blockNumbers in persistence for fast-resume
  • Benchmark documentation
  • Support going forward syncing for Ethereum
  • NPM package
  • Improved failsafes for data consistency
  • Split up stores into separate dependencies

Supported Indexing Stores and Benchmarks

The following indexing implementations have been benchmarked on an Ethereum blockchain section with a relatively large number of events (EtherDelta exchange blocks 4800000 - 5002718) on a single 8-core 2017 Macbook Pro:

Store NameStore IDEvents Per SecondBlocks Per Second
Local Memorymemory4072.7/s464.5/s
Redisredis2049.55/s235.25/s
Local Flat Filefile1798.75/s201.75/s
MongoDBmongodb795.5/s94.6/s
Elasticsearchelasticsearch452.25/s57.1/s
LevelDBlevel207.35/s26.95/s

Install Dependencies

yarn install

Testing & Linting

yarn test
yarn lint

Integration tests (requires synced ethereum node at localhost:8545):

yarn test:integration

Example: Sync trading and balance events from decentralized trading contract: EtherDelta

Contract address: https://etherscan.io/address/0x8d12a197cb00d4747a1fe03395095ce2a5cc6819

See examples/etherdelta/sync.js.

Define which events to index on which keys:

const indexing = {
  events: {
    Withdraw: {
      keys: ['user'],
    },
    Trade: {
      keys: ['tokenGive', 'tokenGet', 'get', 'give'],
    },
  },
};

Then create a store:

const store = new LevelStore(indexing, '/tmp/etherdelta.db');

Now boot up the indexer:

const indexer = new Indexer(store, EtherdeltaABI, '0x8d12a197cb00d4747a1fe03395095ce2a5cc6819');
await indexer.syncAll({
  fromBlock: 4906764,
});

Once indexing is complete events can be retrieved as follows:

const events = await store.get('Withdraw', 'user', '0x13d8d38421eb02973f3f923a71a27917bd483190');

Directory Structure

  • package.json - Configure dependencies
  • dist/* - Files generated by babel
  • src - All source code
  • src/*/__tests__ - Unit tests
  • integration/__tests__ - Integration tests

Downloads/wk

16

GitHub Stars

42

LAST COMMIT

5yrs ago

MAINTAINERS

1

CONTRIBUTORS

0

OPEN ISSUES

1

OPEN PRs

0
VersionTagPublished
0.1.12
latest
5yrs ago
No alternatives found
No tutorials found
Add a tutorial

Rate & Review

100
No reviews found
Be the first to rate