Skip to content

Commit 9c4d3a6

Browse files
reverse rpc fallback order (#1010)
Co-authored-by: Rinat <[email protected]>
1 parent 3408257 commit 9c4d3a6

File tree

4 files changed

+194
-190
lines changed

4 files changed

+194
-190
lines changed

packages/nextjs/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"react-dom": "^18.3.1",
3232
"react-hot-toast": "^2.4.0",
3333
"usehooks-ts": "^3.1.0",
34-
"viem": "2.21.32",
35-
"wagmi": "2.12.23",
34+
"viem": "2.21.54",
35+
"wagmi": "2.13.4",
3636
"zustand": "^5.0.0"
3737
},
3838
"devDependencies": {

packages/nextjs/scaffold.config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export type ScaffoldConfig = {
88
onlyLocalBurnerWallet: boolean;
99
};
1010

11+
export const DEFAULT_ALCHEMY_API_KEY = "oKxs-03sij-U_N0iOlrSsZFr29-IqbuF";
12+
1113
const scaffoldConfig = {
1214
// The networks on which your DApp is live
1315
targetNetworks: [chains.hardhat],
@@ -20,7 +22,7 @@ const scaffoldConfig = {
2022
// You can get your own at https://dashboard.alchemyapi.io
2123
// It's recommended to store it in an env variable:
2224
// .env.local for local testing, and in the Vercel/system env config for live apps.
23-
alchemyApiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY || "oKxs-03sij-U_N0iOlrSsZFr29-IqbuF",
25+
alchemyApiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY || DEFAULT_ALCHEMY_API_KEY,
2426

2527
// This is ours WalletConnect's default project ID.
2628
// You can get your own at https://cloud.walletconnect.com

packages/nextjs/services/web3/wagmiConfig.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { wagmiConnectors } from "./wagmiConnectors";
22
import { Chain, createClient, fallback, http } from "viem";
33
import { hardhat, mainnet } from "viem/chains";
44
import { createConfig } from "wagmi";
5-
import scaffoldConfig from "~~/scaffold.config";
5+
import scaffoldConfig, { DEFAULT_ALCHEMY_API_KEY } from "~~/scaffold.config";
66
import { getAlchemyHttpUrl } from "~~/utils/scaffold-eth";
77

88
const { targetNetworks } = scaffoldConfig;
@@ -17,8 +17,14 @@ export const wagmiConfig = createConfig({
1717
connectors: wagmiConnectors,
1818
ssr: true,
1919
client({ chain }) {
20+
let rpcFallbacks = [http()];
21+
2022
const alchemyHttpUrl = getAlchemyHttpUrl(chain.id);
21-
const rpcFallbacks = alchemyHttpUrl ? [http(), http(alchemyHttpUrl)] : [http()];
23+
if (alchemyHttpUrl) {
24+
const isUsingDefaultKey = scaffoldConfig.alchemyApiKey === DEFAULT_ALCHEMY_API_KEY;
25+
// If using default Scaffold-ETH 2 API key, we prioritize the default RPC
26+
rpcFallbacks = isUsingDefaultKey ? [http(), http(alchemyHttpUrl)] : [http(alchemyHttpUrl), http()];
27+
}
2228

2329
return createClient({
2430
chain,

0 commit comments

Comments
 (0)