Skip to content

A command line utility for converting TypeScript interfaces to OpenRPC interface descriptions.

License

Notifications You must be signed in to change notification settings

rekmarks/ts-to-open-rpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ts-to-open-rpc

A command line utility for converting TypeScript interfaces to OpenRPC interface descriptions.

Note: Early MVP. Many TODOs.

Usage

First, pull repo and yarn link or npm link.

The program outputs to stdout:

ts-to-open-rpc METHOD_NAME TYPESCRIPT_FILE

Example

For the wallet_addEthereumChain RPC method.

With a file interface.ts consisting of:

interface AddEthereumChainParameter {
  chainId: string
  blockExplorerUrl?: string
  chainName?: string
  nativeCurrency?: {
    name: string
    symbol: string
    decimals: number
  }
  rpcUrl?: string
}

This command:

ts-to-open-rpc wallet_addEthereumChain interface.ts > result.json

Produces the following result.json:

{
  "name": "wallet_addEthereumChain",
  "params": [
    {
      "name": "AddEthereumChainParameter",
      "description": "The AddEthereumChainParameter",
      "schema": {
        "$ref": "#/components/schema/AddEthereumChainParameter"
      }
    }
  ],
  "components": {
    "schemas": {
      "AddEthereumChainParameter": {
        "type": "object",
        "required": [
          "chainId"
        ],
        "properties": {
          "chainId": {
            "type": "string"
          },
          "blockExplorerUrl": {
            "type": "string"
          },
          "chainName": {
            "type": "string"
          },
          "nativeCurrency": {
            "$ref": "#/components/schema/NativeCurrency"
          },
          "rpcUrl": {
            "type": "string"
          }
        }
      },
      "NativeCurrency": {
        "type": "object",
        "required": [
          "decimals",
          "name",
          "symbol"
        ],
        "properties": {
          "decimals": {
            "type": "number"
          },
          "name": {
            "type": "string"
          },
          "symbol": {
            "type": "string"
          }
        }
      }
    }
  }
}

About

A command line utility for converting TypeScript interfaces to OpenRPC interface descriptions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published