GithubHelp home page GithubHelp logo

event_indexer's Introduction

Table Schema:

 CREATE TABLE
      tx_log (
          tx_hash varchar(255) NOT NULL,
          logIndex INT NOT NULL,
          sender varchar(255) NOT NULL,
          receiver varchar(255) NOT NULL,
          amount varchar(255) NOT NULL,
          token varchar(255) NOT NULL,
          PRIMARY KEY(tx_hash, logIndex)
     );

     CREATE INDEX sender ON tx_log (sender);

MySQL used for ACID compliance and 3rd normal form.

Primary Key is transaction hash and log index to identify each unique transfer event. sender has been indexed because of it being the prime attributes for querying the data.

Methodology:

Subscribe to each new block formed say n, and get all the transactions of (n-6)th block for a re-org proof indexing.

For each contract interacting transaction, fetch the logs and then for each trasnfer event log find the from which is the caller, to can be fetched from topics and token count can be fetched from data of that log. Now symbol can be fetched using ABI of ERC20 and contract address. Persist these transactions in a mysql DB.

Setup:

  • Create DB with name event_index in mysql
  • Configure dotenv
  • npm run start
  • Sample Get request:
    http://localhost:3000/fetchSendersDetails?sender=0xb07098db26ea326d82d9b5b34520535fdb8980b8
  • Sample response:
{
    "all_txs": [
        {
            "tx_hash": "0x0012d256476d3ea8a139fbf498abd3da15aaab4359db63cea0b708a073b382f2",
            "logIndex": 138,
            "sender": "0xb07098db26ea326d82d9b5b34520535fdb8980b8",
            "receiver": "0x30146933a3a0babc74ec0b3403bec69281ba5914",
            "amount": "32794.0077",
            "token": "TEAM"
        }
    ],
    "transfer_count": 1
}

event_indexer's People

Contributors

fuzious avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.