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

@test117/rpc-handler

v1.0.1

Published

Uses Chainlist's RPC collection racing them returning the lowest latency RPC

Downloads

2

Readme

@ubiquity/rpc-handler

This packages leverages Chainlist's network RPC list to return the lowest latency provider from the list for any given network ID.

Features

  • Returns the lowest latency provider for a given network ID
  • Drops bad endpoints from the list and creates a runtime/local storage cache
  • Can re-test the cached RPCs by calling handler.getFastestRpcProvider()
  • Can be used in both the browser and Node.js
  • Fully configurable and extendable
  • Only uses endpoints which Chainlist report as tracking no data (see extraRpcs.js)

Installation

yarn add @ubiquitydao/rpc-handler

Usage

  • Import the handler for your environment
Browser
import { HandlerConstructorConfig } from "@ubiquity/rpc-handler/dist/esm/src/handler";
import { RPCHandler } from "@ubiquity/rpc-handler/dist/esm/src/rpc-handler";

export function useHandler(networkId: number) {
  const config: HandlerConstructorConfig = {
    networkId,
    autoStorage: true,
    cacheRefreshCycles: 5,
  };
  // No RPCs are tested at this point
  return new RPCHandler(config);
}
import { useHandler } from "./rpc-handler";
const handler = useHandler(networkId);

// Now the RPCs are tested
app.provider = await handler.getFastestRpcProvider();
Node.js
import { HandlerConstructorConfig } from "@ubiquity/rpc-handler/dist/cjs/src/handler";
import { RPCHandler } from "@ubiquity/rpc-handler/dist/cjs/src/rpc-handler";

const config: HandlerConstructorConfig = {
  networkId: 100;
  autoStorage: false, // only applies to local storage
  cacheRefreshCycles: 5,
};

async function main() {
  const handler = new RPCHandler(config);
  return await handler.getFastestRpcProvider();
}

main().then(console.log).catch(console.error);

Notes

  • The RPCs are not tested on instantiation, but are tested on each call to handler.getFastestRpcProvider() or handler.testRpcPerformance()

  • networkId is the only required configuration option

  • See the full config object (optionally passed in the constructor) for more options

  • Local storage is not enabled by default, but can be enabled by passing autoStorage: true in the config object

  • The cacheRefreshCycles is the number of roundtrips made before clearing the cache and re-testing all RPCs again

Testing

  • In order to run the tests the package must first be built, this is required otherwise networkRpcs will be empty as the RPCs are injected at build time
yarn test