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

manyfacedcoin

v1.0.124

Published

Modern library for using cryptocurrency from the browser and server (NodeJS). WebSocket and HTTP Request calls are embedded together, using something called a Cascade structure, to ensure data is always its latest value.

Downloads

7

Readme

ManyFacedCoin

Modern library for using cryptocurrency from the browser and server (NodeJS). WebSocket and HTTP Request calls are embedded together, using something called a Cascade structure, to ensure data is always its latest value.

If you only want SLP token data, try looking at my other library, SLPClient.

Currently supported assets:

  • BCH
  • SLP

Installation

npm install manyfacedcoin

This library was built using NodeJS v8.14.0

Simple Usage

    # 1. Initialize your coin or token:
    var BCH = await new ManyFacedCoin().BCH().build();
    # 2. Make an HTTP request to get a balance:
    var balanceInBCH = await BCH.getBalance(address);

Advanced Features (Cascade)

A lot of cryptocurrency libraries are more verbose than they need to be. Traditional HTTP requests are generally easier to test, so they're done first. WebSocket requests are harder to test, but have the advantage of always giving you the most recent data as it comes in. Nowadays most people in Bitcoin are using BitDB, which provides built-in websockets to a MongoDB instance.

Generally, a real-time web developer will use both HTTP and WebSocket requests in their code. An HTTP request gets the intitial data as the page loads, then callbacks are used to update the data as the network state changes. ManyFacedCoin aims to do this for you automatically, using a .live() chain variable. Traditional requests are available with a .get() chain, and websocket requests are available with the .on() chain.

For example. You can access a given data (e.g. balance)in three different ways:

  1. BCH.balance(address).get() will make an HTTP request to get the latest balance.
  2. BCH.balance(address).on(callback) fires a callback with the latest Websocket data as it comes in
  3. BCH.balance(address).live() is a combination of .get() and .on(), which first performs an HTTP request, then updates its response with the latest data from the WebSocket. This function returns a pointer to an object containing the latest data.

So, instead of firing a callback, the .live() variable allows your object to have a key which always refreshes with the latest value. This should produce much cleaner and simpler code.

var x = {}; 
x.userBalance = BCH.balance(address).live();
x.userHistory = BCH.history(address).live();

.price, .block, .transaction, .fee, .utxo, .coinBalance, .tokenBalance, and .history() are some other methods with this feature. If you're interested in using this, see the Cascade documentation for the latest rules, tricks, and gotchas. Alternatively, just append on, get, or live before the capitalized data name (e.g. getBalance or onBlock) to use the library without chaining.