{"id":18437855,"url":"https://github.com/zilliqa/scilla-json-utils","last_synced_at":"2025-04-14T13:14:31.176Z","repository":{"id":42558194,"uuid":"436591497","full_name":"Zilliqa/scilla-json-utils","owner":"Zilliqa","description":"Scilla JSON utils","archived":false,"fork":false,"pushed_at":"2023-07-11T14:41:02.000Z","size":120,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-02-16T10:42:58.576Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@zilliqa-js/scilla-json-utils","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zilliqa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-09T11:28:45.000Z","updated_at":"2023-09-17T17:29:09.000Z","dependencies_parsed_at":"2024-12-24T23:32:41.671Z","dependency_job_id":null,"html_url":"https://github.com/Zilliqa/scilla-json-utils","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zilliqa%2Fscilla-json-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zilliqa%2Fscilla-json-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zilliqa%2Fscilla-json-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zilliqa%2Fscilla-json-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zilliqa","download_url":"https://codeload.github.com/Zilliqa/scilla-json-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248886341,"owners_count":21177645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T06:16:27.169Z","updated_at":"2025-04-14T13:14:31.140Z","avatar_url":"https://github.com/Zilliqa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e\n  Scilla JSON Utils\n  \u003c/h1\u003e\n  \u003cstrong\u003e\n  Simplifies the way you construct the Scilla JSON data\n  \u003c/strong\u003e\n\u003c/div\u003e\n\u003chr/\u003e\n\u003cdiv\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@zilliqa-js/scilla-json-utils\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://img.shields.io/npm/v/@zilliqa-js/scilla-json-utils\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://app.travis-ci.com/Zilliqa/scilla-json-utils\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://app.travis-ci.com/Zilliqa/scilla-json-utils.svg?token=6BrmjBEqdaGp73khUJCz\u0026branch=main\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/Zilliqa/scilla-json-utils\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://codecov.io/gh/Zilliqa/scilla-json-utils/branch/main/graph/badge.svg?token=YlzpRvkgub\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"LICENSE\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/License-GPLv3-blue.svg\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n## Installation\n\n```sh\nnpm i @zilliqa-js/scilla-json-utils\n# or\nyarn add @zilliqa-js/scilla-json-utils\n```\n\n## Usage\n\n### I. `scillaJSONVal(type: string, value: any)`\n\n#### Integers (`UintX` / `IntX`)\n\n```js\nimport { scillaJSONVal } from \"@zilliqa-js/scilla-json-utils\";\n\nscillaJSONVal(\"Uint256\", \"1\");\n// Output: \"1\"\n```\n\n```js\nscillaJSONVal(\"Int256\", \"-1\");\n// Output: \"-1\"\n```\n\n```js\nscillaJSONVal(\"Uint256\", 1);\n// Output: \"1\"\n```\n\n```js\nscillaJSONVal(\"Int256\", -1);\n// Output: \"-1\"\n```\n\n#### Strings (`String`)\n\n```js\nscillaJSONVal(\"String\", \"Foo\");\n// Output: \"Foo\"\n```\n\n#### Byte Strings (`ByStrX`)\n\n```js\nscillaJSONVal(\"ByStr20\", \"0x85E0bef5F9a11821f9B2BA778a05963436B5e720\");\n// Output: \"0x85e0bef5f9a11821f9b2ba778a05963436b5e720\"\n// Note that the output is lowercased.\n```\n\n#### Block Numbers (`BNum`)\n\n```js\nscillaJSONVal(\"BNum\", \"1\");\n// Output: \"1\"\n```\n\n```js\nscillaJSONVal(\"BNum\", 1);\n// Output: \"1\"\n```\n\n#### Boolean (`Bool`)\n\n```js\nscillaJSONVal(\"Bool\", false);\n```\n\nOutput:\n\n```json\n{\n  \"argtypes\": [],\n  \"arguments\": [],\n  \"constructor\": \"False\"\n}\n```\n\n#### Option (`Option`)\n\n##### None\n\n```js\nscillaJSONVal(\"Option (ByStr20)\", undefined);\n```\n\nOutput:\n\n```json\n{\n  \"argtypes\": [\"ByStr20\"],\n  \"arguments\": [],\n  \"constructor\": \"None\"\n}\n```\n\n##### Some\n\n```js\nscillaJSONVal(\"Option (ByStr20)\", \"0x0000000000000000000000000000000000000000\");\n```\n\nOutput:\n\n```json\n{\n  \"argtypes\": [\"ByStr20\"],\n  \"arguments\": [\"0x0000000000000000000000000000000000000000\"],\n  \"constructor\": \"Some\"\n}\n```\n\n#### Pair (`Pair`)\n\n```js\nscillaJSONVal(\"Pair (ByStr20) (Uint256)\", [\n  \"0x0000000000000000000000000000000000000000\",\n  1,\n]);\n```\n\nOutput:\n\n```json\n{\n  \"argtypes\": [\"ByStr20\", \"Uint256\"],\n  \"arguments\": [\"0x0000000000000000000000000000000000000000\", \"1\"],\n  \"constructor\": \"Pair\"\n}\n```\n\n#### List (`List`)\n\n```js\nscillaJSONVal(\"List (Pair (ByStr20) (Uint256))\", [\n  [\"0x85E0bef5F9a11821f9B2BA778a05963436B5e720\", 1],\n  [\"0x85E0bef5F9a11821f9B2BA778a05963436B5e720\", 2],\n]);\n```\n\nOutput:\n\n```json\n[\n  {\n    \"argtypes\": [\"ByStr20\", \"Uint256\"],\n    \"arguments\": [\"0x85e0bef5f9a11821f9b2ba778a05963436b5e720\", \"1\"],\n    \"constructor\": \"Pair\"\n  },\n  {\n    \"argtypes\": [\"ByStr20\", \"Uint256\"],\n    \"arguments\": [\"0x85e0bef5f9a11821f9b2ba778a05963436b5e720\", \"2\"],\n    \"constructor\": \"Pair\"\n  }\n]\n```\n\n#### User-defined ADTs\n\n```ocaml\ntype Foo =\n| Bar of ByStr20 BNum\n| Baz of ByStr20\n```\n\n```js\nscillaJSONVal(\n  \"0x85E0bef5F9a11821f9B2BA778a05963436B5e720.Foo.Bar.of.ByStr20.BNum\",\n  [\"0x0000000000000000000000000000000000000000\", 1]\n);\n```\n\nOutput:\n\n```json\n{\n  \"argtypes\": [],\n  \"arguments\": [\"0x0000000000000000000000000000000000000000\", \"1\"],\n  \"constructor\": \"0x85e0bef5f9a11821f9b2ba778a05963436b5e720.Bar\"\n}\n```\n\n### II. `scillaJSONParams({[vname: string]: [type: string, value: any]})`\n\n```ocaml\ntype Foo =\n| Bar of ByStr20 BNum\n| Baz of ByStr20\n```\n\n```js\nimport { scillaJSONParams } from \"@zilliqa-js/scilla-json-utils\";\n\nscillaJSONParams({\n  x: [\n    \"0x85E0bef5F9a11821f9B2BA778a05963436B5e720.Foo.Bar.of.ByStr20.BNum\",\n    [\"0x0000000000000000000000000000000000000000\", 1],\n  ],\n  y: [\n    \"List (Pair (ByStr20) (String))\",\n    [\n      [\"0x85E0bef5F9a11821f9B2BA778a05963436B5e720\", \"Foo\"],\n      [\"0x85E0bef5F9a11821f9B2BA778a05963436B5e720\", \"Bar\"],\n    ],\n  ],\n  z: [\"Uint256\", 1],\n});\n```\n\nOutput:\n\n```json\n[\n  {\n    \"type\": \"0x85e0bef5f9a11821f9b2ba778a05963436b5e720.Foo\",\n    \"value\": {\n      \"argtypes\": [],\n      \"arguments\": [\"0x0000000000000000000000000000000000000000\", \"1\"],\n      \"constructor\": \"0x85e0bef5f9a11821f9b2ba778a05963436b5e720.Bar\"\n    },\n    \"vname\": \"x\"\n  },\n  {\n    \"type\": \"List (Pair (ByStr20) (String))\",\n    \"value\": [\n      {\n        \"argtypes\": [\"ByStr20\", \"String\"],\n        \"arguments\": [\"0x85e0bef5f9a11821f9b2ba778a05963436b5e720\", \"Foo\"],\n        \"constructor\": \"Pair\"\n      },\n      {\n        \"argtypes\": [\"ByStr20\", \"String\"],\n        \"arguments\": [\"0x85e0bef5f9a11821f9b2ba778a05963436b5e720\", \"Bar\"],\n        \"constructor\": \"Pair\"\n      }\n    ],\n    \"vname\": \"y\"\n  },\n  {\n    \"type\": \"Uint256\",\n    \"value\": \"1\",\n    \"vname\": \"z\"\n  }\n]\n```\n\n[More cases](src/index.test.ts)\n\n## License\n\nThis project is open source software licensed as [GPL-3.0](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzilliqa%2Fscilla-json-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzilliqa%2Fscilla-json-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzilliqa%2Fscilla-json-utils/lists"}