Skip to content

Add retry-with-backoff wrapper to contractClient RPC calls #420

Description

@Lakes41

Difficulty: Intermediate
Type: Refactor
Recommended labels (if available in this repo): enhancement, reliability, sdk

Background

src/contracts/contractClient.ts makes direct RPC calls via the configured provider. The provider layer (src/contracts/providers/jsonRpcProvider.ts, webSocketProvider.ts) handles low-level transport, but there is no consistent retry policy applied at the client call level for transient RPC failures.

Problem

Transient RPC errors (timeouts, rate limits, temporary node unavailability) currently propagate immediately to the caller with no retry, causing avoidable failures in access checks under normal network flakiness.

Expected Outcome

contractClient.ts calls are wrapped with a configurable exponential-backoff retry policy for a defined set of retryable error types (timeouts, 429s, connection resets), while non-retryable errors (e.g. revert reasons) fail immediately.

Suggested Implementation

Add a small retry utility (withRetry(fn, options)) with max attempts, base delay, and jitter. Apply it around the RPC call sites in contractClient.ts. Use src/errors/errorCodes.ts to classify which errors are retryable vs. terminal.

Acceptance Criteria

  • Retryable errors (timeout, connection reset, rate limit) are retried with exponential backoff up to a configurable max attempts
  • Non-retryable errors (e.g. contract revert) are not retried
  • Retry behavior is configurable via sdkConfig.ts
  • Unit tests simulate transient failures followed by success, and permanent failures
  • pnpm test:run passes

Likely Affected Files/Directories

  • src/contracts/contractClient.ts
  • src/contracts/contractHelpers.ts
  • src/errors/errorCodes.ts
  • src/config/sdkConfig.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesOfficial Campaign | FWC26Official FWC26 campaign issue — eligible for campaign scoring and rewards

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions