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

@zilliqa-js/core

v3.5.0

Published

Core abstractions that power the zilliqa JS client.

Downloads

4,787

Readme

@zilliqa-js/core

Core abstractions required for interacting with the blockchain.

Classes

BaseProvider

Base class for concrete Providers.

BaseProvider

Parameters
  • nodeURL: string - the URL of the lookup node to send requests to.
  • reqMiddleware: Map<Matcher, ReqMiddlewareFn[]> - an ES6 Map of Matcher, ReqMiddlewareFn[] pairs.
  • reqMiddleware: Map<Matcher, ResMiddlewareFn[]> - an ES6 Map of Matcher, ResMiddlewareFn[] pairs.
Returns
  • BaseProvider

Members

middleware: { request: { use(fn: ReqMiddlewareFn, match: Matcher = '*') }, response: use(fn: ResMiddlewareFn, match: Matcher = '*') }

An object that allows setting middleware on requests and responses. Middleware allows fine-grained control over the request-reponse cycle.

Request middleware is called with details of the RPC request. Response middleware, in addition to the response, is called with the originating request object.

Matcher is either an RPC method, a regular expression, or the wildcard matcher, the string '*'.

Example

In the following example, all requests sent through the module will transparently JSON encode CreateTransaction requests in a format required by the Zilliqa RPC server.

// myMiddleware.js
// myMiddleware listens for CreateTransaction RPC requests, transforming
// `amount`, `gasLimit` and `gasPrice` to `string`, so that the RPC server will
// be able to process the transaction.
export function myMiddleware(req) {
  // This check is, in fact, not required if you make use of `Matcher`.
  if (
    req.payload.method === RPCMethod.CreateTransaction &&
    isTxParams(req.payload.params[0])
  ) {
    const txConfig = req.payload.params[0];

    const ret = {
      ...req,
      payload: {
        ...req.payload,
        params: [
          {
            ...txConfig,
            amount: txConfig.amount.toString(),
            gasLimit: txConfig.gasLimit.toString(),
            gasPrice: txConfig.gasPrice.toString(),
          },
        ],
      },
    };

    return ret;
  }

  return req;
}
// myModule.js
import { myMiddleware } from './myMiddleware.js';

export class MyModule {
  // other code
  ...

  // use the middleware function. As `'CreateTransaction'` was passed as the
  // `Matcher`, myMiddleware will only be called on `CreateTransaction`
  // requests.
  constructor(provider: Provider) {
    this.provider = provider;
    this.provider.middleware.request.use(
      myMiddleware,
      'CreateTransaction',
    );
  }

  // other code
  ...
}

HTTPProvider

Concrete Provider. Extends BaseProvider.

Instance methods

send<P extends any[], R = any, E string>(method: RPCMethod, ...params: P): Promise<RPCResponse<R,E>>

Parameters
  • method: RPCMethod - a valid Zilliqa JSON-RPC method (string).
  • params: any[] - an array of arbitrary parameters to send.
Returns
  • Promise<RPCResponse<R,E>> - resolves with the reponse, or rejects with an error, if any.

Decorators

sign

Method decorator used to decorate methods whose first argument is Signable, i.e., have a bytes property.

Example

  @sign
  async createTransaction(tx: Transaction): Promise<Transaction> {
    // `Transaction` satifies `Signable`.
    // As it is the first argument of `createTransaction`, `tx` is already
    // signed by the time `createTransaction` begins to execute.

    // code to send the transaction to the node or pass it on to another
    // method/function
  }