npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rmrk-team/rmrk-balance-js

v0.0.11-beta-rc17

Published

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

Downloads

29

Readme

@rmrk-team/rmrk-balance-js

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

  • [x] Statemine
  • [x] Moonriver
  • [x] Karura
  • [x] Bifrost

Install

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

Quickstart

CLI

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

Promise

import * as $RMRK from "@rmrk-team/rmrk-balance-js";

async function main() {
  const address = "CAeCc....nK3B";

  $RMRK.provideDefaults();

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

  const total = $RMRK.concat(moonbalance, karurabalance);

  console.log($RMRK.format(total));
}

main();

Observables

import { combineLatest, map } from "rxjs";
import * as $RMRK from "@rmrk-team/rmrk-balance-js";

const address = "CAeCc....nK3B";

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

$RMRK.provideDefaults();

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

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

Use existing Polkadotjs ApiPromise or custom node.

import * as $RMRK from "@rmrk-team/rmrk-balance-js";

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

$RMRK.moonriver.balance("0xfv...6c1h").then((balance) => {
  console.log($RMRK.format(balance));
});

Observable balance$ API : Error handling

import {
  catchError,
  combineLatest,
  map,
  Observable,
  of,
  throwError,
} from "rxjs";

import * as $RMRK from "@rmrk-team/rmrk-balance-js";

const address = "...";

$RMRK.provideDefaults();

const addressErrorCatcher = catchError<
  $RMRK.Balance,
  Observable<$RMRK.FormatError>
>((error: unknown) => {
  if ($RMRK.FormatError.is(error)) {
    return of(error);
  }
  return throwError(() => error);
});

const statemineBalance$ = $RMRK.statemine
  .balance$(address)
  .pipe(addressErrorCatcher);

const bifrostBalance$ = $RMRK.bifrost
  .balance$(address)
  .pipe(addressErrorCatcher);

const total$ = combineLatest([statemineBalance$, bifrostBalance$]).pipe(
  map((balances) => {
    const total = balances.reduce<$RMRK.Balance>((acc, next) => {
      return $RMRK.concat(
        acc,
        $RMRK.FormatError.is(next) ? $RMRK.empty() : next
      );
    }, $RMRK.empty());

    return total;
  })
);

total$.subscribe((total) => {
  console.log($RMRK.format(total));
});