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
;;; // web3 instanceconst ethereumProviderUrl = 'https://mainnet.infura.io/v3/YOUR_KEY'; // The Ethereum that we will queryconst web3 = ethereumProviderUrl; // orbs client instanceconst virtualChainId = 1100000; // The virtual chain ID on the Orbs networkconst orbsNodeUrl = `http://18.197.127.2/vchains/`;const orbsClient = orbsNodeUrl virtualChainId NetworkTypeNETWORK_TYPE_TEST_NET; const orbsPosData = ;
Setup - Browser
;;; // creating the web3 instancelet provider;if window as anyethereum // Using existing "window.ethereum" provider [MetaMask]' provider = window as anyethereum; else // Using your own "infura" provider const ethereumProviderUrl = 'https://mainnet.infura.io/v3/YOUR_KEY'; provider = ethereumProviderUrl;const web3 = provider; // create the orbs-client-sdk instanceconst orbsNodeAddress = '18.197.127.2'; // The Orbs node that we will queryconst virtualChainId = 1100000; // The virtual chain Id on the Orbs networkconst orbsNodeUrl = `http:///vchains/`;const orbsClient = orbsNodeUrl virtualChainId NetworkTypeNETWORK_TYPE_TEST_NET; const orbsPosData = ;
Usage
readValidators(): Promise<string[]>
Get a list of Orb's Validators addresses.
readValidatorInfo(validatorAddress: string): Promise<IValidatorInfo>
Get detailed information about the given Validator.
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
.
readRewardsHistory(address: string): Promise<IRewardsDistributionEvent[]>
Get a list of all the rewards distrebution events to a given address
.
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.