EIPs Explained

EIP-758 · Stagnant · Interface · 2017-11-09

EIP-758: Subscriptions and filters for completed transactions

A stagnant JSON-RPC proposal that lets clients subscribe to (or poll for) their mined transactions and receive the called function's return data, which is otherwise thrown away.

What problem does it solve?

A contract calling another contract gets the return value right away. An external caller sending a transaction with eth_sendTransaction or eth_sendRawTransaction gets only a transaction hash. The function's return value is discarded, and if it depended on state at execution time, there is no simple way to recompute it later.

The usual workaround is to emit the value as an event log. According to the spec, this costs extra gas, adds data to the chain, and can produce unwanted logs when the function is also called internally.

Receipts did not fix this either. EIP-658 first proposed putting return data into receipts, but because return data is not paid for, that opened a spam vector. Only a boolean status field was adopted, in Byzantium.

EIP-758 proposes that nodes simply push the return data to the caller when the transaction is mined, without storing it on-chain.

How it works

Subscription (WebSocket or IPC). Call eth_subscribe with the type "completedTransaction" and an optional filter:

  • from: one address or a list of addresses.
  • to: one address or a list. "0x0" matches contract creations.
  • hasReturnData: if true, only transactions that returned data are reported.

When a matching transaction is sealed, the node sends an eth_subscription message containing transactionHash and returnData. If a chain reorganization affects it, the node sends it again with "removed": true. With no filter, the node reports every transaction this RPC client submitted after subscribing.

Polling (HTTP). Call eth_newCompletedTransactionFilter(filter) to get a filter ID, then use the existing eth_getFilterChanges to collect queued results. Over HTTP the node cannot tell who submitted a transaction, so only the filter fields limit the results.

Sample code

Subscribing over a WebSocket (JSON-RPC as defined in the spec):

{"jsonrpc":"2.0","id":1,"method":"eth_subscribe",
 "params":["completedTransaction",{"to":"0xD9Cb531aB97A652c8fC60dcF6D263fcA2F5764e9","hasReturnData":true}]}

A notification after the transaction is mined:

{
  "jsonrpc": "2.0",
  "method": "eth_subscription",
  "params": {
    "subscription": "0x00000000000000000000000000000b0b",
    "result": {
      "transactionHash": "0x00000000000000000000000000000000000000000000000000000000deadbeef",
      "returnData": "0x000000000000000000000000000000000000000000000000000000000000002a"
    }
  }
}

Polling over HTTP:

{"jsonrpc":"2.0","id":1,"method":"eth_newCompletedTransactionFilter","params":[{}]}
{"jsonrpc":"2.0","id":2,"method":"eth_getFilterChanges","params":["0x1"]}

Things to know

  • This proposal is Stagnant and is not part of the standard Ethereum JSON-RPC API. Do not expect nodes or providers to support completedTransaction.
  • In practice, applications still emit events for values they need off-chain. Some clients can also recover return data from debug tracing APIs such as debug_traceTransaction, but those are client-specific.
  • By design, return data would only be delivered live. There is no way to look it up after the fact.
  • It builds on the JSON-RPC conventions in EIP-1474, which is also Stagnant.

#json-rpc #subscriptions #return-data #interface #stagnant

Details

Authors
Jack Peterson <[email protected]>
Status
Stagnant
Type
Standards Track / Interface
Created
2017-11-09
Requires

Machine-readable: Markdown · JSON