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

@beblurt/dblurt

v0.10.9

Published

Blurt blockchain client library (JSON-RPC connector) compatible Nexus

Downloads

124

Readme

@beblurt/dblurt

Client library for the Blurt blockchain (JSON-RPC connector) that runs in both node.js and the browser. Client library implementing Nexus connector for community management as well.

Installation

Via npm

For node.js or the browser with browserify or webpack.

$ npm i @beblurt/dblurt --save

Using browser (cdn or self-hosted script):

Grab dist/dblurt.js from git and include in your html:

<script src="@beblurt/dblurt.js"></script>

Or from the unpkg cdn:

<script src="https://unpkg.com/@beblurt/dblurt@latest/dist/dblurt.js"></script>

Make sure to set the version you want when including from the cdn, you can also use dblurt@latest but that is not always desirable. See unpkg.com for more information.

Usage

In the browser

<script src="https://unpkg.com/@beblurt/dblurt@latest/dist/dblurt.js"></script>
<script>
  var client = new dblurt.Client([
    "https://rpc.beblurt.com",
    "https://rpc.blurt.world",
    "https://blurt-rpc.saboin.com"
  ], { timeout: 1500 });
  client.condenser
    .getDiscussions("trending", { tag: "blurtography", limit: 1 })
    .then(function(discussions) {
      document.body.innerHTML += "<h1>" + discussions[0].title + "</h1>";
      document.body.innerHTML += "<h2>by " + discussions[0].author + "</h2>";
      document.body.innerHTML +=
        '<pre style="white-space: pre-wrap">' + discussions[0].body + "</pre>";
    });
</script>

This example on stackblitz.io

In node.js

With TypeScript:

import { Client } from "@beblurt/dblurt";

const client = new Client([
    "https://rpc.beblurt.com",
    "https://rpc.blurt.world",
    "https://blurt-rpc.saboin.com"
  ], { timeout: 1500 });

for await (const block of client.blockchain.getBlocks()) {
  console.log(`New block, id: ${block.block_id}`);
}

With ES2016 (node.js 7+):

const { Client } = require("@beblurt/dblurt");

const client = new Client([
    "https://rpc.beblurt.com",
    "https://rpc.blurt.world",
    "https://blurt-rpc.saboin.com"
  ], { timeout: 1500 });

async function main() {
  const props = await client.database.getChainProperties();
  console.log(`Maximum blocksize consensus: ${props.maximum_block_size} bytes`);
}

main().catch(console.error);

With node.js streams:

var dblurt = require("@beblurt/dblurt");
var es = require("event-stream"); // npm install event-stream
var util = require("util");

var client = new dblurt.Client([
    "https://rpc.beblurt.com",
    "https://rpc.blurt.world",
    "https://blurt-rpc.saboin.com"
  ], { timeout: 1500 });

var stream = client.blockchain.getBlockStream();

stream
  .pipe(
    es.map(function(block, callback) {
      callback(null, util.inspect(block, { colors: true, depth: null }) + "\n");
    })
  )
  .pipe(process.stdout);

Bundling

The easiest way to bundle dblurt (with browserify, webpack etc.) is to just npm install @beblurt/dblurt and require('@beblurt/dblurt'). However, that is not always desirable since it will not allow your bundler to de-duplicate any shared dependencies dblurt and your app might have.

To allow for deduplication you can require('@beblurt/dblurt/lib/index-browser'), or if you plan to provide your own polyfills: require('@beblurt/dblurt/lib/index'). See src/index-browser.ts for a list of polyfills expected.


Documentation

Detailed documentation: https://dblurt.beblurt.com

Client

RPC Client, can be used in both node.js and the browser.

Client Options

options for the Client (Object)

{
  /** Blurt chain id. Defaults `cd8d90f29ae273abec3eaa7731e25934c63eb654d55080caff2ebb7f5df6381f` */
  chainId?: string
  /** Blurt address prefix. Defaults to main network: `BLT`*/
  addressPrefix?: string
  /** how long to wait in milliseconds before giving up on a rpc call. Defaults to 60 * 1000 ms. */
  timeout?: number
  /**
   * Specifies the amount of times the urls (RPC nodes) should be
   * iterated and retried in case of timeout errors.
   * (important) Requires url parameter to be an array (string[])!
   * Can be set to 0 to iterate and retry forever. Defaults to 3 rounds.
   */
  failoverThreshold?: number
  /** Whether a console.log should be made when RPC failed over to another one */
  consoleOnFailover?: boolean
  /** Retry backoff function, returns milliseconds. Default = {@link defaultBackoff}. */
  backoff?: (tries: number) => number
  /** Node.js http(s) agent, use if you want http keep-alive. @see https://nodejs.org/api/http.html#http_new_agent_options. */
  agent?: any
}

Client Usage

new Client(address: url | url[], options: ClientOptions = {});

Utilities

PublicKey

To manipulate a 'owner' | 'active' | 'posting' | 'memo' account public key

eg: verification of the signature of a user message

import { PublicKey } from "@beblurt/dblurt";
const pKey = PublicKey.from("account public key")
const verified = pKey.verify(message, signature)

PrivateKey

To manipulate a 'owner' | 'active' | 'posting' | 'memo' account private key

eg: signature of a message

import { PrivateKey } from "@beblurt/dblurt";
const pKey = PrivateKey.from("account private key")
const signature = pKey.sign(message)

Encoding/Decoding Memo

For private memo messages between accounts using private/public memo keys

eg: Blurt transfer with encrypted memo

The encodeMemo() and decodeMemo() functions are called directly from the library.

import { encodeMemo, decodeMemo } from "@beblurt/dblurt"
Encode Memo

The function encodeMemo() takes as parameters:

  • memo - The memo to encrypt (need to start with #).
  • senderPrivateMemoKey - The private Memo key of the sender (PrivateKey | string).
  • receiverPublicMemoKey - The publicKey Memo key of the recipient (PublicKey | string).
const memo = "#MY MEMO TO ENCODE"
const encryptedMemo = encodeMemo(memo, senderPrivateMemoKey, receiverPublicMemoKey)
Decode Memo

The function decodeMemo() takes as parameters:

  • memo - The encrypted memo to decrypt (need to start with #).
  • receiverPrivateMemoKey - The private Memo key of the recipient (PrivateKey | string).
const encryptedMemo = "#XYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZ"
const memo = decodeMemo(encryptedMemo, receiverPrivateMemoKey)

cryptoUtils

Misc crypto utility functions.

const cryptoUtils = {
  decodePrivate,
  doubleSha256,
  encodePrivate,
  encodePublic,
  generateTrxId,
  isCanonicalSignature,
  isWif,
  regExpAccount,
  ripemd160,
  sha256,
  signTransaction,
  transactionDigest
}

Tools Class

Some useful functions like mana with regeneration calculation, vote value calculation, etc...

example for mana:

import { Client } from "@beblurt/dblurt";

const client = new Client([
    "https://rpc.beblurt.com",
    "https://rpc.blurt.world",
    "https://blurt-rpc.saboin.com"
  ], { timeout: 1500 });

client.tools.getAccountMana('beblurt').then(mana => {
  const percentMana = ((mana.current_mana / mana.max_mana) * 100).toFixed(2);
  console.log(`voting mana: ${percentMana} %`);
});

example for convert VESTS to BLURT:

import { Client } from "@beblurt/dblurt";

const client = new Client([
    "https://rpc.beblurt.com",
    "https://rpc.blurt.world",
    "https://blurt-rpc.saboin.com"
  ], { timeout: 1500 });

/** Get Dynamic Global Properties */
const DGP   = await client.condenser.getDynamicGlobalProperties() 

/** Convert 1,000,000 VESTS to BLURT */
client.tools.convertVESTS(1000000, DGP).then(BLURT => {
  console.log(`1,000,000 VESTS = ${BLURT} BLURT`);
});

BLURT APPBASE API documentation

Share and Enjoy!

Contributing

Pull requests for new features, bug fixes, and suggestions are welcome!