Socket
Book a DemoInstallSign in
Socket

@rmrk-team/rmrk-balance-js

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rmrk-team/rmrk-balance-js

Read balances of the chains that support the $RMRK token. The following chains are currently supported:

Source
npmnpm
Version
0.0.1-beta-rc9
Version published
Weekly downloads
2
-92.31%
Maintainers
2
Weekly downloads
 
Created
Source

@rmrk/rmrk-balance-js

Read balances of the chains that support the $RMRK token. The following chains are currently supported:

  • Statemine
  • Moonriver
  • Karura
  • Bifrost

Quickstart

yarn add | npm install @rmrk-team/rmrk-balance-js

CLI

npm install -g @rmrk-team/rmrk-balance-js
rmrk-balance -a YOUR_ADDRESS

Observables

import { ApiPromise, WsProvider } from "@polkadot/api";
import { combineLatest, map } from "rxjs";
import {
  statemine,
  karura,
  bifrost,
  moonriver,
} from "@rmrk-team/rmrk-balance-js";

const address = "D6HSL6nGXHLYWSN8jiL9MSNixH2F2o382KkHsZAtfZvBnxM";

// Get a stream of each RMRK balance state
const statemineBalance$ = statemine.balance$(address);
const moonriverBalance$ = moonriver.balance$(address);
const karuraBalance$ = karura.balance$(address);
const bifrostBalance$ = bifrost.balance$(address);

// Combine into total for verification.
const total$ = combineLatest([
  statemineBalance$,
  moonriverBalance$,
  karuraBalance$,
  bifrostBalance$,
]).pipe(
  map(([statemine, moonriver, karura, bifrost]) => {
    return {
      balance:
        statemine.balance +
        moonriver.balance +
        karura.balance +
        bifrost.balance,
    };
  })
);

// Print total user RMRK balance
total$.subscribe((total) => {
  console.log({ total });
});

// Can be done at a later time than starting the subscriptions.
// They will wait for the apis to be ready.

statemine.provideApi(
  ApiPromise.create({
    provider: new WsProvider("wss://statemine-rpc.polkadot.io"),
  })
);

moonriver.provideApi(
  ApiPromise.create({
    provider: new WsProvider("wss://wss.moonriver.moonbeam.network"),
  })
);

karura.provideApi(
  ApiPromise.create({
    provider: new WsProvider("wss://karura.polkawallet.io"),
  })
);

bifrost.provideApi(
  ApiPromise.create({
    provider: new WsProvider("wss://bifrost-rpc.liebi.com/ws"),
  })
);

Promise

import { ApiPromise, WsProvider } from "@polkadot/api";
import { moonriver, karura } from "@rmrk-team/rmrk-balance-js";

async function main() {
  const address = "D6HSL6nGXHLYWSN8jiL9MSNixH2F2o382KkHsZAtfZvBnxM";

  moonriver.provideApi(
    ApiPromise.create({
      provider: new WsProvider("wss://wss.moonriver.moonbeam.network"),
    })
  );
  karura.provideApi(
    ApiPromise.create({
      provider: new WsProvider("wss://karura.polkawallet.io"),
    })
  );

  const [moonbalance, karurabalance] = await Promise.all([
    moonriver.balance(address),
    karura.balance(address),
  ]);

  console.log({
    moonbalance,
    karurabalance,
    total: moonbalance.balance + karurabalance.balance,
  });
}

main();

FAQs

Package last updated on 25 Jan 2022

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