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

toyrpc

v0.0.5

Published

> Toychain JSON-RPC

Downloads

4

Readme

toyrpc

Toychain JSON-RPC

Toyrpc lets you interact with all Toychain APIs via HTTP or TCP, using the JSON-RPC 2.0 spec (https://www.jsonrpc.org/specification).

poster


Why

  1. Programming Language Agnostic: No need to use JavaScript to program Toychain, you can simply set up a Toyrpc daemon and interact with it over JSON-RPC to clone, add, push, read, etc. --- everything you can do with Toychain.
  2. Container-friendly: Toyrpc and its Toychain can be containerized

Intall

You need to install both toychain AND toyrpc, because Toyrpc endpoints are instantiated from an existing Toychain object.

npm install --save toychain
npm install --save toyrpc

Setting up the server

Build or find a toychain, and then instantiate a Toyrpc from the toychain.

const Toychain = require('toychain')
const Toyrpc = require('toyrpc')

// Build a toychain
const toychain = new Toychain({ xpriv: <xpriv> })

// Instantiate RPC for the toychain
const rpc = new Toyrpc({
  chain: toychain,
  readonly: true,
  port: 3000,
  protocol: "http"
})

// Listen
rpc.listen()

Here's the full syntax for the constructor:

const rpc = new Toyrpc({
  chain: <toychain object>,
  readonly: <true|false (default false)>,
  port: <the port to serve rpc from>,
  protocol: <"http"|"tcp">
})
  • chain: you need to inject an existing toychain object to build an RPC endpoint
  • readonly: if set to true, you can make this RPC endpoint only readonly. All "write" actions (clone, add, push, and reset) are blocked. When readonly mode, the only allowed functions are count and get.
  • port: The port to serve RPC from
  • protocol: Choose to serve over HTTP or TCP. The default is HTTP.

Once initialized, you can listen:

rpc.listen()

API Usage

Once the endpoint is up and running, you can make JSON-RPC 2.0 compliant requests over HTTP or TCP.

Here's an example:

POST http://localhost:3012

{
  "jsonrpc": "2.0",
  "method": "add",
  "params": {
    "v": 1,
    "out": [{
      "o0": "OP_0", "o1": "OP_RETURN", "s2": "hello toy"
    }],
    "edge": { "in": 1, "out": 2 }
  },
  "id": 0
}

The curreently available RPC endpoints are:

  • clone: (write method) calls the clone method https://toychain.network/#/?id=_2-clone
  • add: (write method) calls the add method https://toychain.network/#/?id=_3-add
  • push: (write method) calls the push method https://toychain.network/#/?id=_4-push
  • reset: (write method) calls the reset method https://toychain.network/#/?id=_6-reset
  • get: (read method) calls the get method https://toychain.network/#/?id=_7-get
  • count: (read method) calls the count method https://toychain.network/#/?id=_5-count

See JSON-RPC 2.0 Spec for more details on the JSON-RPC syntax: https://www.jsonrpc.org/specification


Demo

You can try the demo under demo/http.

  1. The server.js starts a JSON-RPC server.
  2. The client.js lets you call various available JSON-RPC methods via HTTP