EIP-758 Subscription/filter for completed transactions (Subscriptions and filters for completed transactions)
No call decision · Networking & nodes · EIP status Stagnant · created 2017-11-09
A proposal for an RPC feature that, once a transaction is mined and completed, delivers the return value of the contract function it executed to the caller via subscription or polling.
Why it is needed
If you send a transaction now with eth_sendTransaction or eth_sendRawTransaction, the node only returns the transaction hash, and the return value of the contract function the transaction executed is discarded. The return value often depends on blockchain state, so the caller cannot simply compute it in advance. A common workaround today is for the contract to record the return value in an event log, but this piles unnecessary data onto the chain, charges the caller extra gas, and when the called function internally calls other functions, those functions' logs get piled up too, leaving useless logs behind. There is also an asymmetry in that internal callers can access the return value within the transaction execution context, but external callers cannot.
What changes
Today
- Sending a transaction only returns the hash; the function's return value is discarded
- To obtain the return value, the contract must record it in an event log
- Logs from internally called functions can also pile up unnecessarily
- Unlike internal callers, external callers have no way to access the return value
After EIP-758
- Subscribing to completedTransaction via eth_subscribe gives a notification of the return value when the transaction is mined
- In HTTP environments, polling is possible with eth_newCompletedTransactionFilter and eth_getFilterChanges
- Notifications can be filtered to only the desired transactions using from, to, and hasReturnData
- On chain reorganization, a re-notification is sent with removed:true attached
Who is affected
- Wallet & app developers: Transaction execution results (return values) can be received and processed directly without leaving a log.
- Client (node) teams: RPC methods such as completedTransaction via eth_subscribe, eth_newCompletedTransactionFilter, and eth_getFilterChanges need to be implemented.
- Users: There is no change users feel directly, but dApps will be able to show transaction execution results faster and more accurately.
In depth
Subscription method (eth_subscribe)
The caller sends completedTransaction as the first parameter and a filter dictionary as the second parameter to the eth_subscribe RPC. The filter optionally accepts three fields: from, to, and hasReturnData. from and to can each be a single address or a list of addresses, filtering for transactions whose sender is in the from list and whose recipient is in the to list. Setting hasReturnData to true limits notifications to completed transactions that have a return value. After the request, the node returns a subscription ID, and notifications are sent only for transactions mined after the subscription was made.
Polling method (filters)
HTTP callers without a full-duplex connection (WebSocket, IPC) create a filter with eth_newCompletedTransactionFilter and receive a filter ID. When a transaction completes, the node queues a notification including the return value, and each time the caller calls eth_getFilterChanges, the queue is drained and the transactionHash and returnData array are returned in the order they were computed. With the polling method, the node has no way to confirm whether the client that sent the transaction is the same as the client that created the filter, so submitter-based restrictions do not apply.
What the notification contains
Once the transaction is mined, the node sends an eth_subscription method with transactionHash and returnData in params.result. If the transaction called a contract function, returnData holds the actual return value. Even when there is no return value (for example a simple value transfer, or a function with no return value), the design still allows the completion notification itself to be received.
Handling chain reorganization
If a transaction that was already mined is subsequently affected by a chain reorganization, the node sends another notification for the same transaction with a removed:true field added. This lets subscribers know that the return value they previously received no longer belongs to a valid block.
Relationship to EIP-658
EIP-658 was originally a proposal to put the return value into the transaction receipt, but since the return value is not data stored on the blockchain and is not charged gas, putting it in the receipt could have opened a path for denial-of-service (DoS) attacks or spam. So the revised EIP-658 added only a simple boolean status field and was included in the Byzantium hard fork. This EIP-758 proposes solving the return-value access problem that status alone cannot address, through notifications rather than receipt storage.
Design rationale: efficiency
The core advantage of this approach is efficiency. No additional data is stored on the blockchain, and the additional computational burden on nodes is small. However, it does not support retrieving the return value long after the transaction has completed, which matches the usual usage pattern of function return values: the caller can only access them at the moment the function returns, and they are not stored afterward.
Document status
This EIP was written in November 2017 and its status is Stagnant. It lists the JSON-RPC specification from EIP-1474 as a requirement. Note that it is not currently being actively discussed or adopted as a standard.