Skip to content

internal/ethapi: return null for missing raw transactions - #35227

Open
manusw7 wants to merge 4 commits into
ethereum:masterfrom
manusw7:fix/raw-tx-null-not-found
Open

internal/ethapi: return null for missing raw transactions#35227
manusw7 wants to merge 4 commits into
ethereum:masterfrom
manusw7:fix/raw-tx-null-not-found

Conversation

@manusw7

@manusw7 manusw7 commented Jun 26, 2026

Copy link
Copy Markdown

Summary

eth_getRawTransactionByHash, eth_getRawTransactionByBlockHashAndIndex, eth_getRawTransactionByBlockNumberAndIndex, and debug_getRawTransaction were returning the JSON string "0x" instead of null when the requested transaction is not found.

Rationale

The structured counterparts (eth_getTransactionByHash / ByBlockHashAndIndex / ByBlockNumberAndIndex) already return null for not-found, as explicitly specified in execution-apis via the notFound schema (type: 'null'). The raw variants should follow the same convention. Nethermind, Reth, and Besu all return null.

A companion PR on execution-apis formally adds the three methods to the spec with oneOf: [notFound, bytes]: ethereum/execution-apis#836.

Changes

  • newRPCRawTransactionFromBlockIndex: hexutil.Bytes*hexutil.Bytes
  • GetRawTransactionByBlockNumberAndIndex: hexutil.Bytes*hexutil.Bytes
  • GetRawTransactionByBlockHashAndIndex: hexutil.Bytes*hexutil.Bytes
  • GetRawTransactionByHash: (hexutil.Bytes, error)(*hexutil.Bytes, error), with explicit MarshalBinary error propagation on the success path
  • DebugAPI.GetRawTransaction (debug_getRawTransaction): (hexutil.Bytes, error)(*hexutil.Bytes, error), with explicit MarshalBinary error propagation — same fix as GetRawTransactionByHash.

A nil *hexutil.Bytes pointer marshals to JSON null; a non-nil pointer marshals to the 0x-prefixed hex string as before.

Tests

Added TestRPCGetRawTransactionByHash, TestRPCGetRawTransactionByBlockHashAndIndex, TestRPCGetRawTransactionByBlockNumberAndIndex, and TestRPCDebugGetRawTransaction following the existing golden-file pattern. Each covers the found, out-of-range/unknown, and zero-hash cases. All not-found golden files assert null.

manusw7 and others added 3 commits June 25, 2026 17:48
Change GetRawTransactionByHash, GetRawTransactionByBlockNumberAndIndex,
GetRawTransactionByBlockHashAndIndex and the helper
newRPCRawTransactionFromBlockIndex to return *hexutil.Bytes instead of
hexutil.Bytes so that a nil pointer serialises to JSON null rather than
"0x" when the requested transaction is not found.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Change DebugAPI.GetRawTransaction return type from hexutil.Bytes to
*hexutil.Bytes so that a not-found transaction serialises as JSON null
instead of "0x". Add TestRPCDebugGetRawTransaction with golden files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants