npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cosmos-indexer

v0.5.7

Published

Iterates blocks from given height and catches up latest blocks. Takes every block header and/or transactions, and passes it to your handler. Works with multiple RPCs from chain-registry, balancing between them, or with your own prioritized RPC. Optionally

Downloads

56

Readme

Self-hosted indexer for Cosmos SDK based blockchains

Iterates blocks from given height and catches up latest blocks. Takes every block header and/or transactions, and passes it to your handler. Works with multiple RPCs from chain-registry, balancing between them, or with your own prioritized RPC. Optionally, caches blocks into your db to reindex data faster (+ removes ibc-proofs from txs).

Project status

Core features are stable (iterating over blocks, working with chain-registry) in production. Secondary features need some testing.

Roadmap to "1.0" version:

- Split into 2 parts - data fetcher and executor, so they can work asynchronously. First will responsible to deliver data from pool of RPCs, and second will apply this data to user's callback. 
- Better types, so user won't need to cast objects in callback
- Make Dockerfile and feature to build watchers from config
- Depinjection
- User should pass only typeUrl and event type/key he would like to watch, with callback.

Future ideas:

- Create a web interface with monitoring

Usecases

  1. Alerts - to catch some event in blockchain faster as possible.
  2. To collect data needed for on-chain analysis, dashboards.
  3. Minters/Scripts
  4. Alternative to websocket connection

Usage

Install with

npm install cosmos-indexer

or

yarn add cosmos-indexer

See usage examples go to src/examples

import { BlocksWatcher, BlockWithIndexedTxs } from "../blocksWatcher";

(async () => {
    await BlocksWatcher
        .create()
        .useNetwork({
            //network name, as mentioned here https://github.com/cosmos/chain-registry/
            name: "stargaze",
            //RAW_TXS - txs without execution result
            //INDEXED_TXS - txs with eventlogs
            //ONLY_HEIGHT - block heights with date, for minters
            //In case of ONLY_HEIGHT It will poll rpcs every second for new height (/status endpoint), 
            //so please don't run this for a long time. 
            dataToFetch: "INDEXED_TXS",
            //you can pass custom RPC, it will prioritize it over registry's rpcs
            //rpcUrls: [ "your-rpc.com:26657" ],
            //you can start from specific block, but be sure that there's at least one node stores data from this block
            fromBlock: 11177007,
            //lag for 10 block if it's ok for you to have a "near-real-time" data, 
            //it will wait for all nodes to sync and you'll get less errors
            //default 0
            lag: 10,
            //now you can handle block with txs, how you want
            //if dataToFetch set to "INDEXED_TXS", cast block to "as BlockWithIndexedTxs" 
            //if dataToFetch set to "RAW_TXS", cast block to "as BlockWithDecodedTxs"
            //if dataToFetch set to "ONLY_HEIGHT", cast block to tuple "as Block"  
            onDataRecievedCallback: async (ctx, block) => {
                let b = block as BlockWithIndexedTxs;
                console.log(ctx.chain.chain_name, b.header.height, b.txs.map((x: any) => x.hash))
            }
        })
        //block cache, in case if you need to reindex data in future
        //typeorm mongodatasourceoptions object 
        //https://orkhan.gitbook.io/typeorm/docs/data-source-options#mongodb-data-source-options
        .useBlockCache({
            type: "mongodb",
            enabled: true,
            //removes useless update_client logs and ics23:iavl data from txs
            trimIbcProofs: true,
            url: "mongodb://localhost:27017/"
        })
        //it will fetch from chain-registry 
        .useChainRegistryRpcs()
        //if fromBlock specified, it will fetch 5 block in parallel, please don't use large batches, rpc could throw 429's 
        .useBatchFetching(5)
        .start()
})();