parse-cosmwasm-schema
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

parse-cosmwasm-schema

Parser for JSON schemas generated from CosmWasm, useful for creating automated contract tooling.

Table of Contents

Quickstart

Add to your package.json by using Yarn or NPM.

$ yarn add parse-cosmwasm-schema

Then, in your program:

import parseSchema from "parse-cosmwasm-schema";

// any schema generated by CosmWasm
const schema = {
  ...
};

parseSchema(schema).then(parseTree => {
  // the resultant parse tree is JSON
  console.log(JSON.stringify(parseTree, null, 2));
})

Introduction

Smart contracts on Terra (powered by CosmWasm) use JSON messages to define interactions. Each smart contract defines its interface through a JSON schema which specifies the structure and expected format of the messages that it can respond to. By reading the JSON schema, we are able to extract information which can be used to automatically generate tools that would otherwise require tedious manual labor.

parse-cosmwasm-schema provides an algorithm that reads in a CosmWasm-generated JSON schema and produces a JSON-based parse tree of the original Rust data. Because it is written in TypeScript, it also provides a set of types that are helpful for walking the parse tree, for writing your own custom solutions.

Output Structure

The output is a parse tree represented as a JSON object, which can be one of several NodeType definitions.

All nodes follow the format:

{
  "type": "<node-type>",
  "value": {
    "title": "<node-title>", // or undefined
    "description": "<node-description>", // or undefined
    "ref": "<ref-name>" // if derived from a resolved reference, will be a string.
    ... // additional properties depending on node type
  }
}

Simple Nodes

None

  • type: none

Boolean

  • type: boolean

String

  • type: string

Integer

  • type: integer
  • properties:
    • size: type of integer (e.g. u32, u64, etc.)

Composite Nodes

The following node types can include other node types.

Enum

  • type: enum
  • properties:
    • variants: a list of possible other node types

Struct

  • type: struct
  • properties:
    • members: an object where keys are member names and values are nodes

Optional

  • type: optional
  • properties:
    • body: a node type

Array

  • type: array
  • properties:
    • contents: node type of array's elements
    • size: number size of array

Vec

  • type: vec
  • properties:
    • contents: node type of vector's elements

Tuple

  • type: tuple
  • properties:
    • contents: an array of node types

List of Tools

parse-cosmwasm-schema is used to power a number of useful contract tools.

By Terraform Labs

Name Description
gen-contract-docs Generates documentation for smart contract messages
gen-contract-sdk Generates Python and JavaScript SDKs for smart contracts
gen-contract-cli Generates a command-line interface for smart contract
gen-contract-ui Web-based UI tool for interacting with smart contracts

Community

Made something cool but not on here? Make a pull request to add it to the list.

Name Description
Currently no community tools -- be the first one!

Readme

Keywords

none

Package Sidebar

Install

npm i parse-cosmwasm-schema

Weekly Downloads

56

Version

0.2.0

License

MIT

Unpacked Size

259 kB

Total Files

21

Last publish

Collaborators

  • williamterra