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

vote4us

v1.0.4

Published

Vote for us (for Antelope BPs)

Downloads

25

Readme

Vote for Us

Description

This library provides everything needed to integrate a button into a website, allowing users to vote for a block producer on a blockchain from the Antelope family (such as Telos). It also offers functionality to retrieve the current status of the block producer, including the number of votes, percentage of total votes, and ranking position.

To use the library, the developer only needs to create an instance of the Vote4Us class, passing parameters that specify the block producer’s name along with additional parameters that identify the blockchain where the producer is a candidate. Optionally, you can include a list of suggested and not suggested block producers, as shown in the following example:

// Configuration for Vote4Us instance
const config: Vote4UsConfig = {
    currentProducer: 'producername',
    suggestedBPs: [
        'suggestedbp1',
        'suggestedbp2',
        'suggestedbp3',
        'suggestedbp4',
        'suggestedbp5',
        'suggestedbp6',
    ],
    notSuggestedBPs: [
        'notsuggested',
    ],
    rpcEndpoint: 'https://mainnet.telos.net',
    chainId: '4667b205c6838ef70ff7988f6e8257e8be0e1284a2f59699054a018f743b1d11',
    expectedBPs: 160,
};

// Create an instance of Vote4Us
const vote4us = new Vote4Us(config);

Explanation of Each Parameter

  • currentProducer: The account name of the block producer that you want to promote and gather votes for.
  • suggestedBPs: If the user has space to vote for more block producers, suggestions from this list will be added (with the user consent) until the maximum of 30 block producers is reached.
  • notSuggestedBPs: If the user has remaining slots available to vote for more block producers, active producers will be randomly selected and added, excluding those in this list.
  • rpcEndpoint: The RPC endpoint of the network where the block producer is a candidate.
  • chainId: The chain ID of the blockchain you are interacting with.
  • expectedBPs: Sometimes the list of producers may be incomplete due to truncation. This parameter ensures that the query is repeated as many times as necessary until a minimum of expectedBPs producers is retrieved.

Open de dialog

vote4us.openDialog();

Check current status

console.log(vote4us.state.rank);        // (number) current position in the rank of active producers
console.log(vote4us.state.votes);       // (number) total votes for the current producer
console.log(vote4us.state.percentage);  // (string) readable string containing the percentage of votes over total votes

Subscribe for changes

vote4us.change.subscribe((state: Vote4UsState) => {
    // ...
});

Interfaces

export interface LoggedAccount {
    name: string;
    permission: string;
    user: Session;
}

export interface Statics {
    rank: number;
    votes: number;
    totalVotes: number;
    percentage: string;
    list: string[];
}

export type BlockProducers = string[];
export interface Vote4UsConfig {
    appName?: string;
    currentProducer: string;
    suggestedBPs: string[];
    notSuggestedBPs: string[];
    rpcEndpoint: string;
    chainId: string;
    expectedBPs: number;
}

export interface Vote4UsState {
    originalBPSelection: BlockProducers;
    modifiedBPSelection: BlockProducers;
    roomForMoreBPs: number;
    logged: LoggedAccount | null;
    currentProducerStatics: Statics;
    showDialog: boolean;
    thanks: boolean;
    hasVotedForUs: boolean;
    addRecommendedBPs: boolean;
    error: string;
}

Build the Library

nvm install v20.12.2
nvm use v20.12.2
npm i
npm run build