Socket
Socket
Sign inDemoInstall

@polkadot/rpc-provider

Package Overview
Dependencies
12
Maintainers
2
Versions
2988
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @polkadot/rpc-provider

Transport providers for the API


Version published
Weekly downloads
98K
decreased by-2.79%
Maintainers
2
Created
Weekly downloads
 

Changelog

Source

11.0.1 Apr 23, 2024

Breaking Changes:

Note! The following breaking changes only refer to @polkadot/api-derive calls under api.derive.staking.* due to the most recent breaking changes in runtime version v1.2. Please refer to the link next to the bullet points for more information.

  • Update api.derive.staking calls with breaking changes (#5860)
  • Add claimedRewardsEra to api.derive.staking.query for compatibility with legacyClaimedRewards (#5862)

Contributed:

  • Bump @substrate/connect to 0.8.10 (Thanks to https://github.com/kratico)

Changes:

  • Update polkadot types-known for latest runtime upgrades

Readme

Source

@polkadot/rpc-provider

Generic transport providers to handle the transport of method calls to and from Polkadot clients from applications interacting with it. It provides an interface to making RPC calls and is generally, unless you are operating at a low-level and taking care of encoding and decoding of parameters/results, it won't be directly used, rather only passed to a higher-level interface.

Provider Selection

There are three flavours of the providers provided, one allowing for using HTTP as a transport mechanism, the other using WebSockets, and the third one uses substrate light-client through @substrate/connect. It is generally recommended to use the [[WsProvider]] since in addition to standard calls, it allows for subscriptions where all changes to state can be pushed from the node to the client.

All providers are usable (as is the API), in both browser-based and Node.js environments. Polyfills for unsupported functionality are automatically applied based on feature-detection.

Usage

Installation -

yarn add @polkadot/rpc-provider

WebSocket Initialization -

import { WsProvider } from '@polkadot/rpc-provider';

// this is the actual default endpoint
const provider = new WsProvider('ws://127.0.0.1:9944');
const version = await provider.send('client_version', []);

console.log('client version', version);

HTTP Initialization -

import { HttpProvider } from '@polkadot/rpc-provider';

// this is the actual default endpoint
const provider = new HttpProvider('http://127.0.0.1:9933');
const version = await provider.send('chain_getBlockHash', []);

console.log('latest block Hash', hash);

@substrate/connect Initialization -

Instantiating a Provider for the Polkadot Relay Chain:

import { ScProvider } from '@polkadot/rpc-provider';
import * as Sc from '@substrate/connect';

const provider = new ScProvider(Sc, Sc.WellKnownChain.polkadot);

await provider.connect();

const version = await provider.send('chain_getBlockHash', []);

Instantiating a Provider for a Polkadot parachain:

import { ScProvider } from '@polkadot/rpc-provider';
import * as Sc from '@substrate/connect';

const polkadotProvider = new ScProvider(Sc, Sc.WellKnownChain.polkadot);
const parachainProvider = new ScProvider(Sc, parachainSpec, polkadotProvider);

await parachainProvider.connect();

const version = await parachainProvider.send('chain_getBlockHash', []);

FAQs

Last updated on 23 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc