@xops.net/snaps-openrpc-generator
v1.17.4
Published
Generate High end snaps in a snap.
Downloads
8
Readme
Snaps OpenRPC Generator
Generate High end snaps in a snap.
A Generator tool for creating Metamask Snaps using open-rpc APIs.
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
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 package.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.
and play around with the interactive api documentation at http://localhost:8000/api-documentation
Resources
- Getting Started Video (Demo) - EthDenver Hackathon 2020 - outdated on build steps but still really useful resource
- @open-rpc/generator package
- example open-rpc documents