New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@polkadot/rpc-core

Package Overview
Dependencies
Maintainers
1
Versions
3019
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polkadot/rpc-core

A JavaScript wrapper for the Polkadot JsonRPC interface

  • 0.31.28
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
103K
decreased by-9.71%
Maintainers
1
Weekly downloads
 
Created
Source

@polkadot/rpc-core

This library provides a clean wrapper around all the methods exposed by a Polkadot network client.

Usage

Installation -

yarn add @polkadot/rpc-core

Initialisation -

import Rpc from '@polkadot/rpc-core';
import WsProvider from '@polkadot/rpc-provider/ws';

const provider = new WsProvider('http://127.0.0.1:9944');
const api = new Rpc(provider);

Retrieving the block header object for a given block header hash (a 0x-prefixed hex string with length of 64) -

api.chain
  .getHeader('0x1234567890')
  .then((header) => console.log(header))
  .catch((error) => console.error(error));

Retrieving the best block number, parent hash, state root hash, extrinsics root hash, and digest (once-off) -

api.chain
  .getHead()
  .then((headerHash) => {
    return api.chain.getHeader(headerHash);
  })
  .then((header) => {
    console.log(`best #${header.blockNumber.toString()}`);
    console.log(`parentHash: ${header.parentHash.toString()}`);
    console.log(`stateRoot: ${header.stateRoot.toString()}`);
    console.log(`extrinsicsRoot: ${header.extrinsicsRoot.toString()}`);
    console.log(`digest: ${header.digest.toString()}`);
  })
  .catch((error) => {
    console.error('error:', error);
  });

Retrieving best header via subscription -

api.chain
  .subscribeNewHead((header) => {
    console.log(`best #${header.blockNumber}`);
  })
  .then((subscriptionId) => {
    console.log(`subscriptionId: ${subscriptionId}`);
    // id for the subscription, can unsubscribe via
    // api.chain.subscribeNewHead.unsubscribe(subscriptionId);
  })
  .catch((error) => {
    console.error('error subscribing:', error);
  });

Keywords

FAQs

Package last updated on 13 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc