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

@filecoin-shipyard/lotus-client-schema

v4.2.0

Published

Lotus JS Client API Schema

Downloads

465

Readme

Lotus JS Client Schema

This package contains some .js files that describe methods exported by the Lotus JSON-RPC API.

See filecoin-shipyard/js-lotus-client for examples that show how to use these schemas.

Usage

const { LotusRPC } = require('@filecoin-shipyard/lotus-client-rpc')
const { NodejsProvider } = require('@filecoin-shipyard/lotus-client-provider-nodejs')
const { mainnet } = require('@filecoin-shipyard/lotus-client-schema')

const url = 'ws://127.0.0.1:7777/rpc/v0'
const provider = new NodejsProvider(url)
const client = new LotusRPC(provider, { schema: mainnet.fullNode })

Schemas

The following schema objects are exported:

  • mainnet.fullNode - used to talk to a Lotus "Full Node" (lotus)
  • mainnet.storageMiner - used to talk to a Lotus storage miner (lotus-miner)
  • mainnet.gatewayApi - used to talk to public Lotus API Gateway (lotus-gateway)
  • mainnet.walletApi - a subset of methods for wallets
  • mainnet.workerApi - used to talk to lotus-worker (for mining)
  • mainnet.common - a subset of methods used by a number of different daemons

Schema Format

Right now, the schema is extremely simple, as the JS library only needs to know if a method supports subscriptions or not. The JS library is very light, so all method parameters are just passed through to the JSON-RPC request.

In the future, the schema could be extended to provide more parameter and type information to make it easier to validate and marshal/unmarshal requests and responses.

For example, the entry for the ChainHead method is currently just:

  ChainHead: {}

The ChainNotify entry supports JSON-RPC subscriptions, so it looks like this:

  ChainNotify: {
    subscription: true
  }

Each API is represented by an Object with a single methods property which is an Object with all the methods supported.

If you are trying to use a JSON-RPC API method that isn't in the schema yet, don't be afraid to "monkey-patch" the schemas distributed via this package to add any missing methods ... eg. mainnet.fullNode.methods.MyMissingMethod = {}

Updating the schemas

Lotus is constantly being updated. There is a simple tool (written in go) in the go-schemagen directory that links against a Lotus source code tree (modify the replace directory in go.mod or make a symlink) and outputs the current set of method signatures as JSON. The generate-schema-for-api.sh script can be used to generate the JavaScript schemas. To simplify the process, there is an npm script to run the update:

npm run build:schema

TypeScript definitions

The TypeScript definitions generated by go-tsgen are used by the @filecoin-shipyard/lotus-client-rpc package. See https://github.com/filecoin-shipyard/js-lotus-client-rpc#re-generating-typescript-definitions for details on how to update the definitions in that package using the tool located here.

License

Licensed under either of

  • Apache 2.0, (LICENSE-APACHE / http://www.apache.org/licenses/LICENSE-2.0)
  • MIT (LICENSE-MIT / http://opensource.org/licenses/MIT)

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.