Skip to content

Commit

Permalink
reverse rpc fallback order (#1010)
Browse files Browse the repository at this point in the history
Co-authored-by: Rinat <rinat@hey.com>
  • Loading branch information
technophile-04 and rin-st authored Dec 11, 2024
1 parent 3408257 commit 9c4d3a6
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 190 deletions.
4 changes: 2 additions & 2 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"react-dom": "^18.3.1",
"react-hot-toast": "^2.4.0",
"usehooks-ts": "^3.1.0",
"viem": "2.21.32",
"wagmi": "2.12.23",
"viem": "2.21.54",
"wagmi": "2.13.4",
"zustand": "^5.0.0"
},
"devDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion packages/nextjs/scaffold.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export type ScaffoldConfig = {
onlyLocalBurnerWallet: boolean;
};

export const DEFAULT_ALCHEMY_API_KEY = "oKxs-03sij-U_N0iOlrSsZFr29-IqbuF";

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

// This is ours WalletConnect's default project ID.
// You can get your own at https://cloud.walletconnect.com
Expand Down
10 changes: 8 additions & 2 deletions packages/nextjs/services/web3/wagmiConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { wagmiConnectors } from "./wagmiConnectors";
import { Chain, createClient, fallback, http } from "viem";
import { hardhat, mainnet } from "viem/chains";
import { createConfig } from "wagmi";
import scaffoldConfig from "~~/scaffold.config";
import scaffoldConfig, { DEFAULT_ALCHEMY_API_KEY } from "~~/scaffold.config";
import { getAlchemyHttpUrl } from "~~/utils/scaffold-eth";

const { targetNetworks } = scaffoldConfig;
Expand All @@ -17,8 +17,14 @@ export const wagmiConfig = createConfig({
connectors: wagmiConnectors,
ssr: true,
client({ chain }) {
let rpcFallbacks = [http()];

const alchemyHttpUrl = getAlchemyHttpUrl(chain.id);
const rpcFallbacks = alchemyHttpUrl ? [http(), http(alchemyHttpUrl)] : [http()];
if (alchemyHttpUrl) {
const isUsingDefaultKey = scaffoldConfig.alchemyApiKey === DEFAULT_ALCHEMY_API_KEY;
// If using default Scaffold-ETH 2 API key, we prioritize the default RPC
rpcFallbacks = isUsingDefaultKey ? [http(), http(alchemyHttpUrl)] : [http(alchemyHttpUrl), http()];
}

return createClient({
chain,
Expand Down
Loading

0 comments on commit 9c4d3a6

Please sign in to comment.