explorer_api_js
TypeScript icon, indicating that this package has built-in type declarations

5.0.0 • Public • Published

ParallelChain Mainnet Explorer API JavaScript Library

Introduction

The ParallelChain Mainnet Explorer API JavaScript Library (explorer_api_js) allows JavaScript developers to interact with the Explorer API hosted by ParallelChain.

The main features include:

Please refer to the tests and latest migration guide (v5.0.0) for usage samples.

Installation

The library is built with npm (8.x) and compatible to node (v16.x). explorer_api_js is available as an npm package

// Using NPM
npm install explorer_api_js

// Yarn
yarn add explorer_api_js

Importing

// Lexical/ ES6/ ESM/ TypeScript
import { ExplorerAPI } from "explorer_api_js";
// Non-lexical/ CommonJS/ Node.js
const ExplorerAPI = require("explorer_api_js").ExplorerAPI;

Example usage

Get Latest Block:

const explorerAPI = new ExplorerAPI("https://explorer-api-t01.digital-transaction.net/explorer_api");
const latestBlock = await explorerAPI.getLatestBlock();
console.log(latestBlock);
// Output
Block {
  header: ...,
  transactions: ...,
  ...
}

Convenience Classes

The ExplorerAPI exposes helper classes for the following purposes:

  • LockupContract to interact with PRFC3 contracts at a known address (using .getLockupContract())
  • Utilities to perform common operations (using .getUtilities())

Yoy can access these classes like so

// note, please replace with the addresses with your own
const lockupContract = explorerAPI.getLockupContract(
  new PublicAddress("zkk3NDsCfnQaWoMl-dzyAIeTqDqIx_blnKEQH7-ckmU")
);
const tokenOwner = lockupContract.token_owner();
console.log(toBase64url()); // "eFThx84PYXNcVKHv0h0rJ7Z_oIo8xKU3tEVQZF05QTE"

const utilites = explorerAPI.getUtilities();
let contractAddr = utilities.computeContractAddress(
  new PublicAddress("oK8Kvd-2cWYloQaPNlGtG3Q5dV6JFKzVrXOAhBRt5hs"),
  new BN("47987")
);
console.log(contractAddr.toBase64Url()); // "lu-2SF7uOB5EBNLGFkLWHzieJ4BNqxQJ48sQiRpzj90"

API Methods

Summary of methods provided by ExplorerAPI:

General Methods Description
submit submit transaction to the node
view submit a view call to the node to execute contract view method
getBalance get the balance from an account
getNonce get the nonce from an account
getLatestBlock get the latest block
getBlockByBlockNumber get the block by block number
getBlockByBlockHash get the block by block hash
getCBIVersion get Contract Binary Interface (CBI) Version of the contract
getCode get contract code from an account
getStorageState get the value of storage state from the corresponding key
getStorageStateTuples get list of tuples of storage state from the corresponding keys
getValidatorSets get the previous validator sets (previous, current and next)
getNextValidatorSet get the next validator sets
getCurrentValidatorSet get the current validator sets
getPreviousValidatorSet get the previous validator sets
getDeposits get deposits from pairs of operator and owner
getPools get pools from operator's address
getTentativeStakes get tentative stakes from pairs of operator and owner
getDelegatedStakes get the owner's stake that is delegated to the operator in validator set
getCurrentEpoch get current epoch number
getBlockSummariesBy get a maximum Limit number of block summaries filtered by Identifier, in and order specified by Order
getBlockHeadersBy get a maximum Limit number of block headers filtered by Identifier, in and order specified by Order
getBlocksBy get a maximum Limit number of blocks filtered by Identifier, in and order specified by Order
getTxsSummariesByPageIdx get transaction summaries by page ID
getTxsBy get a maximum Limit number of transactions filtered by a combination of Identifier and Filter(s), in format specified by Parts and order specified by Order
getAccountBy get account's fields - speculative nonce and pending transactions
getContractsBy get contract descriptors from Explorer Backend
getContractHash get hash value of a contract deployed at specific address
Blockchain Metrics Methods Description
getMetrics get metrics (specify desired metric )
getMetricsGasPerBlock get metrics - Gas Per Block
getMetricsBlockTime get metrics - Average block time
getMetricsAverageTPS get metrics - Average Transaction Per Second
getMetricsTotalSupply get metrics - Total supply XPLL in Grays
getMetricsCirculatingSupply get metrics - Circulating supply of XPLL in grays
getMetricsIssuanceReward get metrics - calculation of Issuance Reward
getMetricsNetworkBaseFee get the network base fee calculated from latest committed block
getMetricsMinimumGas get the minimum gas required for a transaction to pass through

Package Sidebar

Install

npm i explorer_api_js

Weekly Downloads

3

Version

5.0.0

License

ISC

Unpacked Size

201 kB

Total Files

26

Last publish

Collaborators

  • pchainlab