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

@proton/js

v28.0.0

Published

Javascript Interface to the Proton Blockchain

Downloads

985

Readme

RPC

Javascript API for integration with Proton

Installation

NPM

The official distribution package can be found at npm.

NodeJS Dependency

yarn add @proton/js

Using with Typescript

If you're using Node (not a browser) then you'll also need to make sure the dom lib is referenced in your tsconfig.json:

{
	"compilerOptions": {
		"lib": [..., "dom"]
	}
}

Browser Distribution

The dist-web folder contains minified bundles ready for production, along with source mapped versions of the library for debugging.

Import

ES Modules

Importing using ES6 module syntax in the browser is supported if you have a transpiler, such as Babel.

import { Api, JsonRpc, RpcError, JsSignatureProvider } from "@proton/js";

CommonJS

Importing using commonJS syntax is supported by NodeJS out of the box.

const { Api, JsonRpc, RpcError, JsSignatureProvider } = require("@proton/js");
const fetch = require("node-fetch"); // node only; not needed in browsers

Basic Usage

Signature Provider

The Signature Provider holds private keys and is responsible for signing transactions.

Using the JsSignatureProvider in the browser is not secure and should only be used for development purposes. Use a secure vault outside of the context of the webpage to ensure security when signing transactions in production

const defaultPrivateKey = "5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr"; // bob
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);

JSON-RPC

Open a connection to JSON-RPC, include fetch when on NodeJS.

const rpc = new JsonRpc(["http://127.0.0.1:8888"], { fetch });

Check User Verification

validKycProviders

A list of valid KYC Providers are stored here. When the JsonRpc is instantiated, it will check all the kyc providers and remove any blacklisted providers from this list.

It is an array of strings like so:

console.log(this.rpc.validKycProviders);

['metal.kyc']
isLightKYCVerified

This function serves to check a user's verification status by cross-referencing the user's KYC data against a list of valid KYC providers. A light KYC is considered verification with the user's first name, last name, address and birth date.

After instantiating the rpc, it can be called like so:

this.rpc.isLightKYCVerified(account)

The single argument account that this function takes in can accept a string account name or the user data returned from this.rpc.get_table_rows for the usersinfo table.This function returns the user data object with a flag under the key isLightKYCVerified.

API

const api = new Api({ rpc, signatureProvider });

Sending a transaction

transact() is used to sign and push transactions onto the blockchain with an optional configuration object parameter. This parameter can override the default value of broadcast: true, and can be used to fill TAPOS fields given expireSeconds and either blocksBehind or useLastIrreversible. Given no configuration options, transactions are expected to be unpacked with TAPOS fields (expiration, ref_block_num, ref_block_prefix) and will automatically be broadcast onto the chain.

(async () => {
  const result = await api.transact(
    {
      actions: [
        {
          account: "eosio.token",
          name: "transfer",
          authorization: [
            {
              actor: "useraaaaaaaa",
              permission: "active",
            },
          ],
          data: {
            from: "useraaaaaaaa",
            to: "useraaaaaaab",
            quantity: "0.0001 SYS",
            memo: "",
          },
        },
      ],
    },
    {
      blocksBehind: 3,
      expireSeconds: 30,
    }
  );
  console.dir(result);
})();

Error handling

use RpcError for handling RPC Errors

...
try {
  const result = await api.transact({
  ...
} catch (e) {
  console.log('\nCaught exception: ' + e);
  if (e instanceof RpcError)
    console.log(JSON.stringify(e.json, null, 2));
}
...

Contributing

Contributing Guide

Code of Conduct

License

MIT