Skip to content

Align eth_getBalance parameter validation with Ethereum's OpenRPC specification #3838

@mwb-al

Description

@mwb-al

Problem

Problem:
The eth_getBalance method in packages/relay/src/lib/eth.ts currently allows the second parameter blockNumberOrTagOrHash to be null, as indicated by its TypeScript type:

blockNumberOrTagOrHash: string | null

However, the method is decorated with @rpcParamValidationRules enforcing this parameter as required:

@rpcParamValidationRules({
  0: { type: ParamType.ADDRESS, required: true },
  1: { type: ParamType.BLOCK_NUMBER_OR_HASH, required: true },
})

This mismatch is inconsistent with Ethereum's openrpc.json, where the Block parameter is required and must conform to the BlockNumberOrTagOrHash schema.

In contrast, the Hedera-specific OpenRPC spec allows the parameter to be optional, but for Ethereum compatibility, we must follow the Ethereum spec.

Solution

  • Update the implementation of getBalance to no longer allow null for the blockNumberOrTagOrHash parameter:

    blockNumberOrTagOrHash: string
  • Ensure the entire code path respects the required status of this parameter and gracefully handles cases where it's missing or invalid.

  • Add or update unit tests to confirm that a missing or null blockNumberOrTagOrHash leads to validation errors, aligning behavior with Ethereum JSON-RPC expectations.

Alternatives

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions