EIP-1767 GraphQL interface for node data (GraphQL interface to Ethereum node data)

No call decision · Networking & nodes · EIP status Stagnant · created 2019-02-14

Defines a standard schema that lets read-only data provided by an Ethereum node be queried using the GraphQL query language instead of JSON-RPC.

Why it is needed

Today's JSON-RPC interface is only informally specified, so clients differ on how to represent an empty byte string, as "", "0x", or "0x0". Servers also have no way to know which fields a caller will actually use, so they do unnecessary work. For example, calling eth_getBlock also fetches fields stored separately from the block header, such as totalDifficulty, via an extra disk read every time. In geth, all transaction receipts for a block are stored as a single binary blob, so retrieving even one receipt requires reading and parsing the entire blob, making the work to fetch all receipts for a block scale as the square of the transaction count (O(n^2)). These problems could be fixed by modifying JSON-RPC itself, but that would make the interface more complex, so this EIP proposes adopting GraphQL, an already standardized query language, to enable a more efficient and flexible implementation.

What changes

Today

After EIP-1767

Who is affected

In depth

Spec: Node API

A compatible node MUST serve a GraphQL endpoint over HTTP. The default port SHOULD be 8547, and the endpoint path SHOULD be '/graphql'. A node MAY provide an interactive GraphiQL explorer at the root path ('/') for trying out queries directly.

Spec: core scalars and types

The scalars defined are Bytes32 (32-byte hex), Address (20-byte address), Bytes (byte sequence of arbitrary length, with an empty value as '0x'), BigInt (large integer, always output as 0x-prefixed hex), and Long (64-bit unsigned integer). The core types are Account (address, balance, transactionCount, code, storage), Block (number, hash, parent, transactions, logs, account, call, estimateGas, etc.), Transaction (hash, nonce, from, to, value, status, gasUsed, logs, etc.), and Log (index, account, topics, data, transaction).

Spec: Query and Mutation

The Query type provides block (lookup by number or hash), blocks (range lookup), pending (pending state), transaction (lookup by hash), logs (filtered lookup), gasPrice, protocolVersion, and syncing. There is only one write operation, the Mutation type's sendRawTransaction(data: Bytes!), which broadcasts an RLP-encoded transaction to the network and returns the transaction hash.

Extension rules

A node MAY provide a superset of this schema by adding new fields or types. Experimental or client-specific fields MUST be prefixed in the form '_client_' (e.g. '_geth_', '_parity_'), and adding new fields without such a prefix MUST be specified in a separate new EIP that extends this one.

Why signing, compiling, filters, and mining were left out

Reflecting the trend of Ethereum nodes moving away from auxiliary functions like signing and compiling toward a 'Unix-style' approach where each task is handled by a separate process, the eth_compile* family was excluded because it is already deprecated. eth_accounts, eth_sign, and eth_sendTransaction were also excluded, since many consider them deprecated, with local accounts or a separate signing daemon recommended instead. Filter functionality was left out because it requires GraphQL subscriptions and careful consideration of per-node state retention, and mining functionality was left out because it is used infrequently and there is little benefit to reimplementing it in GraphQL; both are left to be defined in separate future EIPs.

Mapping to existing JSON-RPC

According to the table in the Backwards Compatibility section, most read and send related methods, such as eth_getBalance, eth_call, eth_getBlockByHash, eth_getTransactionReceipt, eth_getLogs, eth_sendRawTransaction, and eth_syncing, are marked IMPLEMENTED and mapped to GraphQL queries. In contrast, the compiler family (eth_getCompilers/eth_compileSolidity, etc.), the filter family (eth_newFilter, etc.), the account family (eth_accounts/eth_sign/eth_sendTransaction), and the mining family (eth_mining/eth_getWork, etc.) are all marked NOT IMPLEMENTED.

Implementation status

The original text records that it was implemented and released in Go-ethereum 1.9.0 and Pantheon (now named Besu) 1.1.1, with work in progress in Trinity and Parity. However, this EIP's status is Stagnant, meaning it has stalled without final approval as a Standards Track EIP. The schema and implementation status recorded here may therefore never be officially changed or updated.

Original EIP · ← EIPs