A command line utility for converting TypeScript interfaces to OpenRPC interface descriptions.
Note: Early MVP. Many TODOs.
First, pull repo and yarn link or npm link.
The program outputs to stdout:
ts-to-open-rpc METHOD_NAME TYPESCRIPT_FILEFor 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.jsonProduces 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"
}
}
}
}
}
}