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

dot-validator-selector

v1.0.3

Published

Get the best staking validators programmatically

Downloads

6

Readme

dot-validator-selector

Get the best staking validators programmatically.

Introduction

Selecting validators for staking your DOT/KSM is an arduous process and one that is uncertain and confusing for most users. The aim of this module is to auto select validators based on the criteria below so that the user doesn't have to. Since most users are not well versed in knowing which validators are best, this module should make a better decision on average without the time commitment necessary to select your own.

Criteria

This program selects validators based on the following criteria:

  • Their identity is verified
  • Their commission is within an acceptable range e.g. no less than 0.5% and no greater than 20%
  • The validator is not oversubscribed, allowing you to earn rewards as a nominator
  • The validator has skin in the game, represented by their own stake e.g. they have deposited 1000 DOT of their own capital
  • Each validator is run by a unique entity
  • The validator has never been slashed
  • The validator is currently elected to validate transactions and earn rewards

Further reading here.

Getting started

Install the modules with npm i & run the tests with npm run test.

You can also download the module via NPM.

Usage

js

// initialise the polkadot api object 
const { ApiPromise, WsProvider} = require("@polkadot/api");
const api = await ApiPromise.create({ provider: new WsProvider("YOUR_PROVIDER") });

// initialise the selector
const selector = new ValidatorSelector(api, MAX_COMMISSION, MIN_STAKING, ERA); // set ERA to 0 or undefined if you want to use the current era

// get n number of validators matching the criteria
selector.getValidators(n);

> [{ "accountId": "1REAJ1k691g5Eqqg9gL7vvZCBG7FCCZ8zgQkZWd4va5ESih", "identity": { "additional": [], "display": { "raw": "0x506f6c6b61646f742e70726f202d205265616c676172" }, "legal": { "none": null }, "web": { "raw": "0x68747470733a2f2f706f6c6b61646f742e70726f" }, "riot": { "raw": "0x407265616c6761723a6d61747269782e6f7267" }, "email": { "raw": "0x68656c6c6f40706f6c6b61646f742e70726f" }, "pgpFingerprint": null, "image": { "none": null }, "twitter": { "raw": "0x4070726f706f6c6b61646f74" } }, "staked": 156300000000, "commission": "1%" }, ...]

// check if a user's validators are meeting the criteria
selector.getUserValidatorsMeetCriteria(userAccountId);

> [{ "accountId": "13mK8AssyPekT5cFuYQ7ijKNXcjHPq8Gnx6TxF5eFCAwoLQ", "match": false }, ...]

via cURL

Cached snapshots of a particular era can be retrieved via cURL:

$ curl https://raw.githubusercontent.com/James-Sangalli/dot-validator-selector/gh-pages/cache/dot/623.json 

Or get a cached snapshot of the latest era in the repo:

$ curl https://raw.githubusercontent.com/James-Sangalli/dot-validator-selector/gh-pages/web-sample/dot/latest.json

Example output:

[{
    "accountId": "Cs7UFcNBsBV4Y65GsM3bDzpvinMKFQZyt6x9TrhVhc8ps4E",
    "identity": {
        "display": "⛓ NOVY ⛓ ",
        "legal": "NOVY",
        "web": "https://stake.novy.pw",
        "riot": "@novy4:matrix.org",
        "email": "[email protected]",
        "pgpFingerprint": "",
        "image": "",
        "twitter": "@lost_inchains"
    },
    "staked": 91697150371972,
    "commission": "6%"
}, ...]

See a sample

If you want to see this module in action for Polkadot or Kusama, you can try it out here. It will randomly select 16/24 validators meeting the criteria for Polkadot/Kusama.

Cached validators

Since this module can be slow to select validators, it is possible to cache them for the current era using npm run updateCache and then retrieve them as above with the cURL instructions. You can see some examples in the cache folder here.

Tip

Thank you to the treasury for this tip!