Skip to content

[Bug]: useBalance crashes app when given invalid address instead of handling gracefully #109

@resourcefulmind

Description

@resourcefulmind

Minimal reproduction repo (required)

Not applicable - can reproduce directly in any project using the hook

Steps to reproduce

  1. Install @solana/client and @solana/react-hooks
  2. Create a component that uses useBalance with an invalid address:

const balance = useBalance("not-a-valid-address");

  1. Run the app
  2. App crashes with blank screen

Actual behavior

App crashes completely with uncaught error:

SolanaError: Expected base58-encoded address string of length in the range [32, 44]. Actual length: 19.

The error is not caught by the hook, causing React to crash and show a blank screen.

Expected behavior

The hook should handle invalid addresses gracefully by either:

  1. Returning an error state: { lamports: null, error: "Invalid address", fetching: false }
  2. Or returning null values without crashing
  3. Or validating input and logging a warning

The app should NOT crash from passing an invalid string to the hook.

Environment

  • OS: macOS
  • Node: v22.x
  • Package versions: @solana/client@1.2.0, @solana/react-hooks@1.2.0
  • Runtime: Chrome browser
  • Cluster / endpoint: https://api.devnet.solana.com

Additional context

This is a DX issue because developers may pass user-typed addresses to this hook. Without input validation or error handling, there's no safe way to use this hook with untrusted input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions