diff --git a/.env.example b/.env.example index 30caf6923d..98e4d9707b 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ VITE_BASE_URL= -VITE_ALCHEMY_API_KEY= +VITE_ALCHEMY_RPC_PROXY_URL= VITE_PRIVY_APP_ID= VITE_PRIVY_APP_CLIENT_ID= diff --git a/README.md b/README.md index 805c36824d..0d55f1411c 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ You'll need to provide a Wallet Connect project id to enable onboarding and wall Set environment variables via `.env`. - `VITE_BASE_URL` (required): The base URL of the deployment (e.g., `https://www.example.com`). -- `VITE_ALCHEMY_API_KEY` (optional): Add an Alchemy API key for EVM interactions; the app will fall back to public RPCs if not provided. +- `VITE_ALCHEMY_RPC_PROXY_URL` (optional): Base URL of your Alchemy proxy for EVM RPC requests; the proxy injects the secret Alchemy API key so it is not exposed in the web app (e.g., `https://proxy.example.com`). - `VITE_PK_ENCRYPTION_KEY` (optional): AES encryption key used for signature obfuscation; necessary for enabling the "Remember Me" feature. - `VITE_V3_TOKEN_ADDRESS` (optional): Address of the V3 $DYDX token. - `VITE_TOKEN_MIGRATION_URI` (optional): The URL of the token migration website. diff --git a/src/lib/wagmi.ts b/src/lib/wagmi.ts index e4cfc9d946..0754913eae 100644 --- a/src/lib/wagmi.ts +++ b/src/lib/wagmi.ts @@ -110,33 +110,34 @@ export enum ChainId { } export const getAlchemyRPCUrlForChainId = (chainId: ChainId) => { - const alchemyKey = import.meta.env.VITE_ALCHEMY_API_KEY; - if (!alchemyKey) return undefined; + const alchemyRpcProxyUrl = import.meta.env.VITE_ALCHEMY_RPC_PROXY_URL; + if (!alchemyRpcProxyUrl) return undefined; + switch (chainId) { case ChainId.ETH_MAINNET: - return `https://eth-mainnet.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/eth-mainnet/v2`; case ChainId.ETH_SEPOLIA: - return `https://eth-sepolia.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/eth-sepolia/v2`; case ChainId.POLYGON_MAINNET: - return `https://polygon-mainnet.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/polygon-mainnet/v2`; case ChainId.POLYGON_MUMBAI: - return `https://polygon-amoy.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/polygon-amoy/v2`; case ChainId.OPT_MAINNET: - return `https://opt-mainnet.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/opt-mainnet/v2`; case ChainId.OPT_SEPOLIA: - return `https://opt-sepolia.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/opt-sepolia/v2`; case ChainId.ARB_MAINNET: - return `https://arb-mainnet.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/arb-mainnet/v2`; case ChainId.ARB_SEPOLIA: - return `https://arb-sepolia.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/arb-sepolia/v2`; case ChainId.BASE_MAINNET: - return `https://base-mainnet.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/base-mainnet/v2`; case ChainId.BASE_SEPOLIA: - return `https://base-sepolia.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/base-sepolia/v2`; case ChainId.AVALANCHE_MAINNET: - return `https://avax-mainnet.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/avax-mainnet/v2`; case ChainId.AVALANCHE_FUJI: - return `https://avax-fuji.g.alchemy.com/v2/${alchemyKey}`; + return `${alchemyRpcProxyUrl}/avax-fuji/v2`; default: return undefined; }