Generate High end snaps in a snap.
A Generator tool for creating Metamask Snaps using OpenRPC tools.
It does this via an OpenRPC Generator Custom Component.
- Can generate:
- Documentation
- Snap Scaffold with strongly typed interfaces and service discovery via rpc.discover
- Clients for accessing your snap (Not Implemented)
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
$ npm install @xops.net/snaps-openrpc-generator @open-rpc/generator --save-dev
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:
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
$ 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.
and play around with the interactive api documentation at http://localhost:8000/api-documentation
- Getting Started Video (Demo) - EthDenver Hackathon 2020 - outdated on build steps but still really useful resource
- @open-rpc/generator package
- example open-rpc documents