EIPs Explained

EIP-1901 · Stagnant · Interface · 2019-02-25

EIP-1901: Add OpenRPC Service Discovery To JSON-RPC Services

Proposes that Ethereum JSON-RPC servers expose an rpc.discover method returning an OpenRPC document, a machine-readable description of every method, so docs, clients and mocks can be generated automatically.

What problem does it solve?

EIP-1474 wrote down Ethereum's JSON-RPC methods in prose, but tools cannot read prose. Without a machine-readable description, every library hand-codes method names, parameter types and result shapes, and differences between clients surface only at runtime.

EIP-1901 proposes adopting OpenRPC, an interface description format for JSON-RPC 2.0 APIs, comparable to what OpenAPI does for REST. A node that publishes an OpenRPC document lets humans and programs discover exactly what it supports. The idea first appeared as an Ethereum Classic proposal (ECIP-1053) and applies to any JSON-RPC blockchain node.

How it works

  • A JSON-RPC service adds one method, rpc.discover. The rpc. prefix is reserved by JSON-RPC 2.0 for system extensions, so it cannot clash with eth_* methods.
  • Calling it returns an OpenRPC document: a JSON file listing each method, its parameters and result schemas (JSON Schema), errors and examples.
  • The document can also be served statically, so tooling can be used before a client implements rpc.discover.

From that single document, tooling can generate:

  • interactive API documentation (the OpenRPC playground),
  • typed clients in many languages,
  • server stubs and mock servers for testing without a real network,
  • generated tests.

The spec cites a Multi-Geth implementation of rpc.discover and an OpenRPC document for the Ethereum JSON-RPC API maintained by ETC Labs.

Sample code

Calling the discovery method:

curl -s -X POST -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","id":1,"method":"rpc.discover","params":[]}' "$RPC_URL"

The shape of the result (abridged):

{
  "openrpc": "1.0.0",
  "info": { "title": "Ethereum JSON-RPC", "version": "1.0.0" },
  "methods": [
    {
      "name": "eth_blockNumber",
      "params": [],
      "result": {
        "name": "blockNumber",
        "schema": { "type": "string", "pattern": "^0x([1-9a-f][0-9a-f]*|0)$" }
      }
    }
  ]
}

Things to know

  • Status is Stagnant. rpc.discover is not something you can assume every Ethereum node supports; test your provider (many return "method not found").
  • The approach itself won: the official Ethereum execution-apis specification is maintained as an OpenRPC document, even though this EIP never moved forward.
  • An OpenRPC document describes an API; it does not guarantee a client implements it correctly. Conformance still needs testing.

#json-rpc #openrpc #api #tooling #interface

Details

Authors
Shane Jonas (@shanejonas), Zachary Belford (@belfordz)
Status
Stagnant
Type
Standards Track / Interface
Created
2019-02-25

Machine-readable: Markdown · JSON