Skip to content

WalletConnect connector silently fails when projectId is empty or whitespace #5030

@Zelys-DFKH

Description

@Zelys-DFKH

Bug Report

Summary

When projectId is an empty string or contains only whitespace (which happens when an environment variable is missing or has a trailing newline in a .env file), the WalletConnect connector initializes without throwing any error. The QR modal never appears and connections silently fail, with no indication of what went wrong.

Reproduction

import { createConfig, http } from 'wagmi'
import { mainnet } from 'wagmi/chains'
import { walletConnect } from 'wagmi/connectors'

// Missing env var scenario — VITE_WC_PROJECT_ID is undefined
const projectId = import.meta.env.VITE_WC_PROJECT_ID ?? ''

const config = createConfig({
  chains: [mainnet],
  transports: { [mainnet.id]: http() },
  connectors: [
    walletConnect({ projectId }), // no error thrown here
  ],
})

// Later, when the user tries to connect:
// → QR modal never opens
// → No error surfaces
// → User is stuck with no feedback

Expected Behavior

walletConnect({ projectId: '' }) should throw immediately with a clear error message pointing to https://cloud.walletconnect.com.

Actual Behavior

No error is thrown. The connector is created successfully, but connections silently fail at runtime when the user attempts to connect.

Context

This is a common pain point when deploying to environments where VITE_WC_PROJECT_ID / REACT_APP_WC_PROJECT_ID / NEXT_PUBLIC_WC_PROJECT_ID is not set, or when .env files have trailing newlines that corrupt the value. The current behavior forces developers to add their own manual validation guard.

Proposed Fix

Validate and trim projectId at connector creation time, throwing a BaseError with a clear message and link to cloud.walletconnect.com.

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