Skip to content

Prevent silent fallback when network is omitted or undefined in EVM client calls #520

@dwellerroughs

Description

@dwellerroughs

Overview

In the CDP SDK EVM client, some methods accept a network parameter. When network is omitted, undefined, or accidentally passed as an empty string, the SDK may proceed and fail later (or fall back to an implicit default) with an unclear error. This makes misconfiguration hard to diagnose and can cause transactions or account actions to target an unintended network.

Problem Description

Developers often build wrappers around the SDK and pass network through multiple layers. A missing value can occur due to:

  • environment variable not set
  • conditional branching that skips assignment
  • serialization/deserialization issues in serverless setups

Without upfront validation, errors appear downstream (RPC failures, unexpected chain IDs, or ambiguous “bad request” errors).

Expected Behavior

  • If network is required for an operation, the SDK should fail fast when it is missing/empty.
  • Error messages should clearly state that network is missing and list valid options.
  • No request (RPC/API) should be made when required inputs are invalid.

Steps to reproduce

  1. Create a CDP client and call an EVM method with network: undefined (or omit the field).
  2. Observe that the SDK attempts to proceed instead of throwing a clear validation error.

Example code

```ts
import { CdpClient } from "@coinbase/cdp-sdk";

async function run() {
  const cdp = new CdpClient({ apiKey: process.env.CDP_API_KEY! });

  // network accidentally omitted / undefined
  await cdp.evm.sendTransaction({
    network: undefined as any,
    to: "0x0000000000000000000000000000000000000000",
    value: "0",
    data: "0x",
  });
}

run().catch(console.error);

Proposed Solution

  • Add a shared input validator for EVM client methods that require network.
  • Reject undefined, empty strings, and unknown values with a descriptive error.
  • Consider narrowing TypeScript types so network cannot be omitted where it is required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions