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/scilla-json-utils

v0.2.0

Published

<div align="center"> <h1> Scilla JSON Utils </h1> <strong> Simplifies the way you construct the Scilla JSON data </strong> </div> <hr/> <div> <a href="https://www.npmjs.com/package/@zilliqa-js/scilla-json-utils" target="_blank"> <img src="

Downloads

12

Readme

Installation

npm i @zilliqa-js/scilla-json-utils
# or
yarn add @zilliqa-js/scilla-json-utils

Usage

I. scillaJSONVal(type: string, value: any)

Integers (UintX / IntX)

import { scillaJSONVal } from "@zilliqa-js/scilla-json-utils";

scillaJSONVal("Uint256", "1");
// Output: "1"
scillaJSONVal("Int256", "-1");
// Output: "-1"
scillaJSONVal("Uint256", 1);
// Output: "1"
scillaJSONVal("Int256", -1);
// Output: "-1"

Strings (String)

scillaJSONVal("String", "Foo");
// Output: "Foo"

Byte Strings (ByStrX)

scillaJSONVal("ByStr20", "0x85E0bef5F9a11821f9B2BA778a05963436B5e720");
// Output: "0x85e0bef5f9a11821f9b2ba778a05963436b5e720"
// Note that the output is lowercased.

Block Numbers (BNum)

scillaJSONVal("BNum", "1");
// Output: "1"
scillaJSONVal("BNum", 1);
// Output: "1"

Boolean (Bool)

scillaJSONVal("Bool", false);

Output:

{
  "argtypes": [],
  "arguments": [],
  "constructor": "False"
}

Option (Option)

None
scillaJSONVal("Option (ByStr20)", undefined);

Output:

{
  "argtypes": ["ByStr20"],
  "arguments": [],
  "constructor": "None"
}
Some
scillaJSONVal("Option (ByStr20)", "0x0000000000000000000000000000000000000000");

Output:

{
  "argtypes": ["ByStr20"],
  "arguments": ["0x0000000000000000000000000000000000000000"],
  "constructor": "Some"
}

Pair (Pair)

scillaJSONVal("Pair (ByStr20) (Uint256)", [
  "0x0000000000000000000000000000000000000000",
  1,
]);

Output:

{
  "argtypes": ["ByStr20", "Uint256"],
  "arguments": ["0x0000000000000000000000000000000000000000", "1"],
  "constructor": "Pair"
}

List (List)

scillaJSONVal("List (Pair (ByStr20) (Uint256))", [
  ["0x85E0bef5F9a11821f9B2BA778a05963436B5e720", 1],
  ["0x85E0bef5F9a11821f9B2BA778a05963436B5e720", 2],
]);

Output:

[
  {
    "argtypes": ["ByStr20", "Uint256"],
    "arguments": ["0x85e0bef5f9a11821f9b2ba778a05963436b5e720", "1"],
    "constructor": "Pair"
  },
  {
    "argtypes": ["ByStr20", "Uint256"],
    "arguments": ["0x85e0bef5f9a11821f9b2ba778a05963436b5e720", "2"],
    "constructor": "Pair"
  }
]

User-defined ADTs

type Foo =
| Bar of ByStr20 BNum
| Baz of ByStr20
scillaJSONVal(
  "0x85E0bef5F9a11821f9B2BA778a05963436B5e720.Foo.Bar.of.ByStr20.BNum",
  ["0x0000000000000000000000000000000000000000", 1]
);

Output:

{
  "argtypes": [],
  "arguments": ["0x0000000000000000000000000000000000000000", "1"],
  "constructor": "0x85e0bef5f9a11821f9b2ba778a05963436b5e720.Bar"
}

II. scillaJSONParams({[vname: string]: [type: string, value: any]})

type Foo =
| Bar of ByStr20 BNum
| Baz of ByStr20
import { scillaJSONParams } from "@zilliqa-js/scilla-json-utils";

scillaJSONParams({
  x: [
    "0x85E0bef5F9a11821f9B2BA778a05963436B5e720.Foo.Bar.of.ByStr20.BNum",
    ["0x0000000000000000000000000000000000000000", 1],
  ],
  y: [
    "List (Pair (ByStr20) (String))",
    [
      ["0x85E0bef5F9a11821f9B2BA778a05963436B5e720", "Foo"],
      ["0x85E0bef5F9a11821f9B2BA778a05963436B5e720", "Bar"],
    ],
  ],
  z: ["Uint256", 1],
});

Output:

[
  {
    "type": "0x85e0bef5f9a11821f9b2ba778a05963436b5e720.Foo",
    "value": {
      "argtypes": [],
      "arguments": ["0x0000000000000000000000000000000000000000", "1"],
      "constructor": "0x85e0bef5f9a11821f9b2ba778a05963436b5e720.Bar"
    },
    "vname": "x"
  },
  {
    "type": "List (Pair (ByStr20) (String))",
    "value": [
      {
        "argtypes": ["ByStr20", "String"],
        "arguments": ["0x85e0bef5f9a11821f9b2ba778a05963436b5e720", "Foo"],
        "constructor": "Pair"
      },
      {
        "argtypes": ["ByStr20", "String"],
        "arguments": ["0x85e0bef5f9a11821f9b2ba778a05963436b5e720", "Bar"],
        "constructor": "Pair"
      }
    ],
    "vname": "y"
  },
  {
    "type": "Uint256",
    "value": "1",
    "vname": "z"
  }
]

More cases

License

This project is open source software licensed as GPL-3.0.