Skip to content

feat(seismic-rpc): eth_getBalance returns native by default, opt-in for gas-token balance#403

Open
HenryMBaldwin wants to merge 1 commit into
seismicfrom
hbai__eth-getbalance-native-default
Open

feat(seismic-rpc): eth_getBalance returns native by default, opt-in for gas-token balance#403
HenryMBaldwin wants to merge 1 commit into
seismicfrom
hbai__eth-getbalance-native-default

Conversation

@HenryMBaldwin

@HenryMBaldwin HenryMBaldwin commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Problem

eth_getBalance returned the effective balance max(native, usdc·10^12) (native vs. the SRC20 gas stablecoin, internally named "usdc"). This was causing confusion for users.

Change

  • balance() now returns the native balance — the default, standard behavior. This also resolves the 1206 inconsistency (all account-inspection RPCs now agree on native by default).
  • New optional per-call parameter: eth_getBalance(address, block, includeGasToken?). true → effective max(native, usdc·10^12); absent/false → native. Backward compatible — standard 2-arg callers get native.
  • The gas-allowance path (estimateGas/call) is unchanged, so accounts holding only the gas stablecoin can still estimate/pay gas even though their reported balance is native.

Tests

  • Unit (usdc.rs): seeds a USDC balance via MockEthProvider and checks the effective math (USDC>native → scaled USDC; native>USDC → native; no-USDC → native). This is the first test exercising the USDC balance path.
  • e2e (integration.rs): standard 2-arg eth_getBalance → native; explicit opt-out → native; opt-in accepted.

Live verification

Ran a standalone node against a custom genesis that pre-allocated 5 USDC of storage for an address (native = 1 wei), then queried over curl:

call result
eth_getBalance(addr, latest) 0x1 (native)
eth_getBalance(addr, latest, false) 0x1 (native)
eth_getBalance(addr, latest, true) 0x4563918244f40000 = 5·10^18 (effective)

…or gas-token balance

eth_getBalance previously returned the effective balance max(native, usdc·10^12),
which surprised users expecting standard native-balance semantics (and was
inconsistent with eth_getAccount/eth_getProof, which already return native).

- balance() now returns the native balance.
- A new optional eth_getBalance(address, block, includeGasToken) parameter restores
  the effective balance when set to true; absent/false yields native. Backward
  compatible with standard 2-arg callers.
- The gas-allowance path (estimateGas/call) is unchanged, so accounts holding only
  the SRC20 gas stablecoin can still pay/estimate gas.

Tests: unit test for the effective-balance math (the first coverage of the USDC
balance path), e2e test for native-default + opt-in plumbing.
@HenryMBaldwin HenryMBaldwin requested a review from cdrappi as a code owner June 10, 2026 21:45
@github-actions

Copy link
Copy Markdown
Contributor

Modifies eth_getBalance to return native balance by default, with an opt-in includeGasToken parameter for the effective balance.

LGTM — This is a well-implemented behavioral change with comprehensive test coverage and proper error handling. The code correctly separates concerns between native balance (default) and effective balance (opt-in), uses proper Seismic test setup with correct chain specs, and includes no security vulnerabilities or secret key exposure risks.

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.

1 participant