Skip to content

xops/snaps-openrpc-generator

This branch is 62 commits ahead of, 580 commits behind open-rpc/generator:master.

Folders and files

NameName
Last commit message
Last commit date
Nov 21, 2021
Mar 19, 2019
Jan 19, 2022
Jan 22, 2022
Mar 17, 2019
Aug 27, 2021
Aug 27, 2021
Feb 10, 2020
Jan 19, 2022
Jan 19, 2022
May 2, 2019
Aug 27, 2021
Aug 27, 2021
Aug 27, 2021
Aug 27, 2021
Aug 27, 2021
Mar 18, 2019
Jan 16, 2020

Repository files navigation

Snaps OpenRPC Generator

Generate High end snaps in a snap.

GitHub release GitHub commits since latest release

A Generator tool for creating Metamask Snaps using OpenRPC tools.

It does this via an OpenRPC Generator Custom Component.

Features:

  • Can generate:
    • Documentation
    • Snap Scaffold with strongly typed interfaces and service discovery via rpc.discover
    • Clients for accessing your snap (Not Implemented)

In a new project

Note: if you are on an ARM based Mac, you will need to brew install vips

Make a new folder for your Snap project

$ mkdir MySnap && cd MySnap
npm init

Install

$ npm install @xops.net/snaps-openrpc-generator @open-rpc/generator --save-dev

Usage

Create a generator config

open-rpc-generator-config.json
echo '{
  "openrpcDocument": "./openrpc.json",
  "outDir": "./generated",
  "components": [
      {
        "type": "custom",
        "name": "snap-openrpc-generator",
        "language": "typescript",
        "customComponent": "@xops.net/snaps-openrpc-generator/build/components/snap",
        "customType": "snap"
      },
      {
        "type": "custom",
        "name": "snap-docs-openrpc-generator",
        "language": "docs",
        "customComponent": "@xops.net/snaps-openrpc-generator/build/components/docs",
        "customType": "docs"
    }
  ]
}' > open-rpc-generator-config.json

Write an OpenRPC Document that describes your plugins interface, and includes any documentation, examples, etc you may want. You can start with one of the OpenRPC examples, write your own with the help of the OpenRPC Playground, or start from the hello world snap:

open-rpc.json
echo '{
  "openrpc": "1.2.4",
  "info": {
    "title": "MySnap",
    "version": "1.0.0"
  },
  "methods": [
    {
      "name": "hello",
      "description": "a method that returns world",
      "params": [],
      "result": {
        "name": "helloWorldResult",
        "schema": {
          "type": "string"
        }
      },
      "examples": [
        {
          "name": "helloWorldExample",
          "params": [],
          "result": {
            "name": "world",
            "value": "world"
          }
        }
      ]
    }
  ]
}' > openrpc.json

Run the OpenRPC Generator

$ npx open-rpc-generator generate -c open-rpc-generator-config.json

To run the generated snap:

cd generated/custom/typescript
npm install .
npm start

The resulting plugin is now at at http://localhost:8081 and which hosts the snap.manifest.json and bundle.js needed for snaps.

To build the documentation:

cd into docs directory, install and start

cd generated/custom/docs
npm install .
npm start

you can now open http://localhost:8000 and view your generated, interactive documentation site.

snaps2

and play around with the interactive api documentation at http://localhost:8000/api-documentation image

Resources

About

OpenRPC Snap Codegen

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 83.8%
  • JavaScript 11.6%
  • CSS 4.6%