How to use the @polkadot/rpc-provider.WsProvider function in @polkadot/rpc-provider

To help you get started, we’ve selected a few @polkadot/rpc-provider examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paritytech / substrate-light-ui / packages / light-api / example / src / index.js View on Github external
import { LightApi } from '@polkadot/light-api';
import { WsProvider } from '@polkadot/rpc-provider';
import React from 'react';
import ReactDOM from 'react-dom';
import { switchMap } from 'rxjs/operators';

import App from './App';
import * as serviceWorker from './serviceWorker';
import './index.css';

ReactDOM.render(, document.getElementById('root'));

const lightApi = new LightApi(new WsProvider('ws://localhost:9944')).isReady;

lightApi
  .pipe(switchMap(api => api.light.newHead()))
  .subscribe(header => console.log('Now at ', header.get('number').toJSON()));

lightApi
  .pipe(switchMap(api => api.light.balanceOf('15jd4tmKwLf1mYWzmZxHeCpT38B2mx1GH6aDniXQxBjskkws')))
  .subscribe(b => console.log('Balance of Alice', b.toString()));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
serviceWorker.unregister();
github polkadot-js / api / packages / api / src / base / Decorate.ts View on Github external
constructor (options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod) {
    super();

    this.registry = options.registry || new TypeRegistry();

    const thisProvider = options.source
      ? options.source._rpcCore.provider.clone()
      : (options.provider || new WsProvider());

    this.decorateMethod = decorateMethod;
    this._options = options;
    this._type = type;
    this._rpcCore = new RpcCore(this.registry, thisProvider, this._options.rpc);
    this._isConnected = new BehaviorSubject(this._rpcCore.provider.isConnected());
    this._rx.hasSubscriptions = this._rpcCore.provider.hasSubscriptions;
    this._rx.registry = this.registry;
  }
github polkadot-js / apps / packages / react-api / src / Api.tsx View on Github external
const setApiUrl = (url: string = defaults.WS_URL): void =>
      setApi(new WsProvider(url));
github polkadot-js / apps / packages / react-api / src / Api.tsx View on Github external
constructor (props: Props) {
    super(props);

    const { queuePayload, queueSetTxStatus, url } = props;
    const provider = new WsProvider(url);
    const signer = new ApiSigner(queuePayload, queueSetTxStatus);

    const setApi = (provider: ProviderInterface): void => {
      api = this.createApi(provider, signer);

      this.setState({ api }, (): void => {
        this.subscribeEvents();
      });
    };
    const setApiUrl = (url: string = defaults.WS_URL): void =>
      setApi(new WsProvider(url));

    api = this.createApi(provider, signer);

    this.state = {
      api,

@polkadot/rpc-provider

Transport providers for the API

Apache-2.0
Latest version published 13 days ago

Package Health Score

90 / 100
Full package analysis

Similar packages