The Midnight node exposes a machine-readable API specification via the rpc.discover JSON-RPC method, following the OpenRPC v1.4 standard and EIP-1901 convention.
Call rpc.discover on a running node to retrieve the full OpenRPC document:
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"rpc.discover","id":1}' \
http://localhost:9944 | jq .resultThe response is a JSON object containing every RPC method the node supports, including parameter types, return types, error definitions, and descriptions.
A static copy of the specification is available at docs/openrpc.json for offline use. This file is regenerated from rpc.discover output and kept in sync via CI tests.
The OpenRPC document describes three categories of methods:
| Category | Methods | Coverage |
|---|---|---|
| Midnight custom | midnight_*, systemParameters_*, network_* |
Full — parameter schemas, return types, error codes, descriptions |
| Partner-chain | sidechain_* |
Full — same coverage as custom methods |
| Standard Substrate | system_*, chain_*, state_*, author_*, grandpa_*, mmr_*, beefy_* |
Reference — method names listed with pointers to upstream Substrate documentation |
Paste the contents of docs/openrpc.json (or the rpc.discover response) into the OpenRPC Playground to browse the API interactively.
The OpenRPC Generator can produce typed client libraries from the specification:
npx @open-rpc/generator-client \
--document docs/openrpc.json \
--language typescript \
--output ./generated-clientSupported languages include TypeScript, Rust, Python, and Go.
A Postman collection can be derived from the OpenRPC document using openrpc-to-postman or by importing the JSON into tools that support OpenRPC.
Tests at two levels verify that the specification stays in sync with the node:
Unit tests (run in CI automatically):
- Method count tests — verify custom (16) and standard Substrate (52) method counts match expected totals
- Static file sync test — ensures
docs/openrpc.jsonmatches the document produced bybuild_openrpc_document() - No duplicates test — verifies no duplicate method names exist in the document
Integration test (requires a running node):
rpc_discover_matches_rpc_methods— connects to a running node, calls bothrpc_methodsandrpc.discover, and verifies every method the node actually serves appears in the OpenRPC document. This catches methods registered in code but missing from the OpenRPC metadata.
# Run against a local node on port 9944:
cargo test -p midnight-node --lib openrpc::tests::rpc_discover_matches_rpc_methods -- --ignored
# Run against a different endpoint:
RPC_URL=http://node.example.com:9944 cargo test -p midnight-node --lib openrpc::tests::rpc_discover_matches_rpc_methods -- --ignoredIf a method is added or removed without updating the specification, the unit tests will fail in CI. The integration test provides an additional runtime verification layer.
To update docs/openrpc.json after modifying RPC methods:
cargo test -p midnight-node test_regenerate_openrpc_json -- --ignoredThis runs the ignored generator test which writes the current rpc.discover output to docs/openrpc.json.