orbs-pos-data
TypeScript icon, indicating that this package has built-in type declarations

6.20.0 • Public • Published

Orbs PoS Data V1

A library that provides a simple way to read data about the Orbs PoS V1, like Guardians, rewards, etc.

Installation

npm install orbs-pos-data --save

Requirements

  • If you are using this library on a browser, make sure that you can provide a web3 instance in version 1.2.1 and up (Probably via metamask), also make sure that you have orbs-client-sdk instance.

Setup - NodeJs

import { orbsPOSDataServiceFactory } from "orbs-pos-data";
import Web3 from "web3";
import { Client, NetworkType } from "orbs-client-sdk";
 
// web3 instance
const ethereumProviderUrl = 'https://mainnet.infura.io/v3/YOUR_KEY';   // The Ethereum that we will query
const web3 = new Web3(new Web3.providers.HttpProvider(ethereumProviderUrl));
 
// orbs client instance
const virtualChainId = 1100000; // The virtual chain ID on the Orbs network
const orbsNodeUrl = `http://18.197.127.2/vchains/${virtualChainId.toString()}`;
const orbsClient = new Client(
  orbsNodeUrl,
  virtualChainId,
  NetworkType.NETWORK_TYPE_TEST_NET
);
 
const orbsPosData = orbsPOSDataServiceFactory(web3, orbsClient);

Setup - Browser

import { orbsPOSDataServiceFactory } from "orbs-pos-data";
import Web3 from "web3";
import { Client, NetworkType } from "orbs-client-sdk";
 
// creating the web3 instance
let provider;
if ((window as any).ethereum) {
  // Using existing "window.ethereum" provider [MetaMask]'
  provider = (window as any).ethereum;
} else {
  // Using your own "infura" provider
  const ethereumProviderUrl = 'https://mainnet.infura.io/v3/YOUR_KEY';
  provider = new Web3.providers.HttpProvider(ethereumProviderUrl);
}
const web3 = new Web3(provider);
 
// create the orbs-client-sdk instance
const orbsNodeAddress = '18.197.127.2';  // The Orbs node that we will query
const virtualChainId = 1100000;          // The virtual chain Id on the Orbs network
const orbsNodeUrl = `http://${orbsNodeAddress}/vchains/${virtualChainId.toString()}`;
const orbsClient = new Client(orbsNodeUrl, virtualChainId, NetworkType.NETWORK_TYPE_TEST_NET);
 
const orbsPosData = orbsPOSDataServiceFactoryIOC(web3, orbsClient);

Usage

readValidators(): Promise<string[]>

Get a list of Orb's Validators addresses.


readValidatorInfo(validatorAddress: string): Promise<IValidatorInfo>

Get detailed information about the given Validator.

interface IValidatorInfo {
  name: string;
  ipAddress: string;
  website: string;
  orbsAddress: string;
  votesAgainst: number;
}

readTotalParticipatingTokens(): Promise<number>

Get the current total number of participating ORBS in the POS.


readRewards(address: string): Promise<IRewards>

Get information about all the rewards of a given address.

export interface IRewards {
  delegatorReward: bigint;
  guardianReward: bigint;
  validatorReward: bigint;
}

readRewardsHistory(address: string): Promise<IRewardsDistributionEvent[]>

Get a list of all the rewards distrebution events to a given address.

interface IRewardsDistributionEvent {
  distributionEvent: string;
  amount: number;
  transactionHash: string;
}

readUpcomingElectionBlockNumber(): Promise<number>

Get the upcoming election block number (on Ethereum)


readEffectiveElectionBlockNumber(): Promise<number>

Get the effective election block number (on Ethereum)


readElectedValidators(): Promise<string[]>

Get a list of the currently elected Validator's addresses.


readElectedValidatorInfo(validatorAddress: string): Promise<IElectedValidatorInfo>

Get a detailed information about the given Validator.


readOrbsBalance(address: string): Promise<bigint>

Get the amount of ORBS the given address is holding.


subscribeToORBSBalanceChange(address: string, callback: (newBalance: string) => void): Promise<() => void>

Listen to ORBS balance changes on the given address. The given callback will be fired on the balance. This function returns the unsubscribe function. call it to unsubscribe.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
6.20.01latest

Version History

VersionDownloads (Last 7 Days)Published
6.20.01
6.19.00
6.18.00
6.17.00
6.16.00
6.15.00
6.14.00
6.13.00
6.12.00
6.11.00
6.10.00
6.9.00
6.8.00
6.7.00
6.6.00
6.5.00
6.4.00
6.3.00
6.2.00
6.1.30
6.1.20
6.1.10
6.1.00
6.0.00
5.2.00
5.1.20
5.1.10
5.1.00
5.0.20
5.0.10
4.5.00
4.4.00
4.3.00
4.2.00
4.1.00
3.2.00
4.0.00
3.1.00
3.0.40
3.0.20
3.0.10
3.0.00
2.0.00
1.3.30
1.3.20
1.3.10
1.3.00
1.2.00
1.2.120
1.2.110
1.1.140
1.1.130
1.1.120
1.1.110
1.1.100
1.1.90
1.1.80
1.1.70
1.1.50
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.10
1.0.00

Package Sidebar

Install

npm i orbs-pos-data

Weekly Downloads

1

Version

6.20.0

License

MIT

Unpacked Size

188 kB

Total Files

47

Last publish

Collaborators

  • gilamran
  • orlavy