EIP-1901 Adding JSON-RPC OpenRPC discovery (Add OpenRPC Service Discovery To JSON-RPC Services)
No call decision · Networking & nodes · EIP status Stagnant · created 2019-02-25
A proposal to add an rpc.discover method to the JSON-RPC API of Ethereum nodes, so a node can expose machine-readable documentation of the features it supports.
Why it is needed
Services that connect to blockchains over JSON-RPC, including Ethereum, each support different methods and parameters depending on the client, forcing developers to read source code directly or inspect network traffic to find out what features were available. EIP-1474 documented the JSON-RPC specification, but it was not a machine-readable standard format. As a result, building wallets, tools, and test code required people to read the documentation and match it by hand each time, and slight differences in method signatures between clients caused compatibility problems. Developers needed a stable development experience and an industry-standard way to describe the API.
What changes
Today
- Differing JSON-RPC method signatures between clients cause compatibility problems
- No machine-readable standard documentation exists to describe what the API supports
- Developers must check source code or network traffic directly to learn which methods are supported
After EIP-1901
- A node returns an OpenRPC document describing the features it supports via the rpc.discover method
- Based on this document, clients, server stubs, mock servers, documentation, and tests in various languages can be generated automatically
- The API can be understood and interacted with without looking at the source code
Who is affected
- Wallet & app developers: Instead of manually matching client code to the methods a node supports, developers can automatically discover them and generate the code.
- Client teams (such as Geth): They implement the rpc.discover method, exposing their JSON-RPC API to the outside as standard documentation.
- Tooling developers: They can build tools such as playgrounds, mock servers, and test generators based on OpenRPC documents.
In depth
The rpc.discover method
A JSON-RPC API that wants to support OpenRPC must implement a service discovery method, and this method's name must be rpc.discover. The rpc. prefix is reserved for system extensions under the JSON-RPC 2.0 specification. Calling this method returns the API's OpenRPC document.
What is an OpenRPC document
The OpenRPC specification defines a standard, language-independent way to describe interfaces for JSON-RPC 2.0 APIs. This lets both humans and computers discover and understand what features a service offers without access to source code, additional documentation, or inspecting network traffic. When a service is properly described with OpenRPC, consumers can understand and interact with the remote service with minimal implementation logic.
The underlying problem
Although EIP-1474 documented the JSON-RPC specification, Ethereum still lacked a machine-readable JSON-RPC specification usable as an industry standard. Developers needed a stable development experience and an industry-standard way to describe Ethereum's JSON-RPC 2.0 API. Ethereum clients exposed RPC endpoints with differing method signatures, causing compatibility problems between clients.
Static or dynamic provision
An OpenRPC document is in JSON format and can be either prepared statically in advance or generated dynamically by an application, then returned through the rpc.discover method. This lets projects and the community adopt the tools, documentation, and clients organized at etclabscore/ethereum-json-rpc-specification even before the rpc.discover method is actually implemented in a specific client.
Uses of machine-readable documentation
A machine-readable JSON-RPC API definition document can be used to generate server stubs and skeletons in multiple languages, clients in multiple languages, mock servers in multiple languages, tests in multiple languages, and documentation. A shared vocabulary and documentation keep developers, testers, architects, and technical writers all aligned on the same content.
Implementation example: multi-geth
The multi-geth client implemented OpenRPC Discovery. An interactive documentation playground can call rpc.discover against multi-geth to automatically discover and display the Ethereum JSON-RPC API documentation. Clients generated from the openrpc.json specification serve as an alternative to web3.js or ethers.js in various languages, and an OpenRPC mock server allows testing without spinning up an actual network.
Current status of the proposal
This EIP is in the Interface category of the Standards Track, written on 2019-02-25, carrying over a proposal originally made as etclabscore's ECIP-1053 into Ethereum. As of the source text, its status is Stagnant, meaning active discussion has stalled.