Skip to content

fix: fall back to public RPCs behind the free-plan Alchemy key and bundle only the env it reads - #321

Merged
dimlbc merged 1 commit into
mainfrom
fix/rpc-public-fallback
Dec 2, 2026
Merged

dimlbc merged 1 commit into
mainfrom
fix/rpc-public-fallback

Conversation

@dimlbc

@dimlbc dimlbc commented Dec 2, 2026

Copy link
Copy Markdown
Member

Issue

No Trello card. The "mStable dApp Main" Alchemy key in the withdraw sites' bundle was found and used by a bot at up to 38M CU a day, billed to the paid account.

Description

withdraw.dhedge.org (dhedge) and withdraw.mstable.org (lts) ship their Alchemy keys in the bundle, and Alchemy has no per-key cap. Both sites move to one key from a separate free-plan Alchemy account. That account stops at 30M CU a month and never bills, and once the month is used up it errors. Until now both providers were Alchemy keys, so nothing stood behind them.

  • Reads go to Alchemy (NX_ALCHEMY_MAIN_API_KEY) first and to public RPCs when it errors or stalls: PublicNode for Ethereum, Arbitrum and Optimism, Tenderly for Polygon. The second Alchemy key, NX_ALCHEMY_FALLBACK_API_KEY, is gone.
  • The Vite config built every NX* variable from the build env into the page, which put NX_CLOUD_ACCESS_TOKEN into both live bundles. It now builds in only NODE_ENV, NX_ALCHEMY_MAIN_API_KEY and NX_WALLET_CONNECT_PROJECT_ID, the variables these two apps read.
  • The dev and preview workflows used ALCHEMY_FALLBACK_API_KEY in both key slots. All six workflows now use ALCHEMY_MAIN_API_KEY.

Verifying

Before the previews build, set the ALCHEMY_MAIN_API_KEY secret to the free-plan key.

Steps to verify

  1. Open the dHEDGE and lts preview links this PR's workflows post, and connect a wallet that holds a withdrawable balance.
  2. In DevTools → Network, reads go to *.g.alchemy.com with the free key.
  3. Block *.g.alchemy.com and reload.
  4. Search the loaded JS for NX_CLOUD.

Expected results

  • With Alchemy reachable, balances load through Alchemy.
  • With Alchemy blocked, balances still load, through the public RPCs.
  • NX_CLOUD is not found.

Both apps lint and build locally. In a local build run with an extra NX_* variable set, the bundles contained only the three listed names.

Implementation details

getPublicRpcProvider() in libs/shared/utils/src/web3.ts follows getAlchemyRpcProvider(). wagmi's configureChains turns the two providers into an ethers FallbackProvider, which starts the second provider when the first errors or stalls.

Todos (if a PR is in work in progress state)

After merging:

  • Run "dHEDGE Main" and "lts Main".
  • Rotate the Nx Cloud access token that shipped in the bundles, and update the NX_CLOUD_ACCESS_TOKEN secret.
  • Delete the ALCHEMY_FALLBACK_API_KEY secret, and rotate the key it held where it lives.
  • Rotate the paid "mStable dApp Main" key.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 595bcf8):

https://apps-lts--pr321-fix-rpc-public-fallb-wewpmo3q.web.app

(expires Thu, 10 Dec 2026 14:53:48 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 8debd0062e03d9ce09ac2458f17da263c61e4b71

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 595bcf8):

https://dhedge-v1-withdraw--pr321-fix-rpc-public-fallb-w8xm995q.web.app

(expires Thu, 10 Dec 2026 14:54:48 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 2157533cdfb02b956c33a37a482e9873c6f9154b

@dimlbc
dimlbc merged commit 71d1696 into main Dec 2, 2026
3 checks passed
@dimlbc
dimlbc deleted the fix/rpc-public-fallback branch December 2, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant