Testnet Chain ID Configuration
Problem
Staging environment sends mainnet chain IDs to APIs that only support testnet, causing
502 errors or unexpected behavior despite VITE_TESTNET_MODE=true being correctly set.
Context / Trigger Conditions
- •Relayr staging API returns 502 Bad Gateway
- •Network payload shows
chain: 1(mainnet) instead ofchain: 11155111(Sepolia) - •
VITE_TESTNET_MODE=trueis confirmed set in Railway/build environment - •Testnet explorers, RPCs, and other chain-specific features work correctly
Root Cause
The ALL_CHAIN_IDS and CHAINS constants in src/constants/index.ts were hardcoded
to mainnet values, not using the environment-aware SUPPORTED_CHAIN_IDS from
src/config/environment.ts.
Solution
- •
Check
src/constants/index.tsfor hardcoded chain ID arrays:typescript// BAD - hardcoded export const ALL_CHAIN_IDS = [1, 10, 8453, 42161] as const // GOOD - environment-aware import { SUPPORTED_CHAIN_IDS } from '../config/environment' export const ALL_CHAIN_IDS = SUPPORTED_CHAIN_IDS - •
Ensure
CHAINSobject usesCHAIN_IDSfrom environment config as keys, not literals - •
Verify components use
ALL_CHAIN_IDSfrom constants, not hardcoded arrays
Key Files
- •
src/config/environment.ts- Source of truth forIS_TESTNET,CHAIN_IDS,SUPPORTED_CHAIN_IDS - •
src/constants/index.ts- Must import and re-export environment-aware values - •
src/constants/chains.ts- Contract addresses (already environment-aware)
Chain ID Mapping
| Network | Mainnet | Testnet (Sepolia) |
|---|---|---|
| Ethereum | 1 | 11155111 |
| Optimism | 10 | 11155420 |
| Base | 8453 | 84532 |
| Arbitrum | 42161 | 421614 |
Verification
- •Build staging:
npm run build:staging - •Check network payload in browser devtools when creating a bundle
- •Confirm chain IDs are Sepolia variants (11155111, etc.)
Notes
- •Railway has
VITE_TESTNET_MODE=trueset as a service variable - •
.env.stagingis gitignored; Railway uses dashboard env vars - •Vite requires
VITE_*variables at BUILD time, not just runtime