Skip to content

Commit

Permalink
Merge branch 'production'
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPereira committed Oct 9, 2024
2 parents d7b5f78 + de84604 commit cdcd0da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 1 addition & 2 deletions packages/nextjs/scaffold.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ const scaffoldConfig = {
// it has no effect if you only target the local network (default is 4000)
pollingInterval: 30000,

// This is ours Alchemy's default API key.
// 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 || "",

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

const { targetNetworks } = scaffoldConfig;

Expand All @@ -19,7 +19,7 @@ export const wagmiConfig = createConfig({
client({ chain }) {
return createClient({
chain,
transport: http(getAlchemyHttpUrl(chain.id)),
transport: fallback([http(getAlchemyHttpUrl(chain.id)), http(), http(getRpcFallbackUrl(chain.id))]),
...(chain.id !== (hardhat as Chain).id
? {
pollingInterval: scaffoldConfig.pollingInterval,
Expand Down
13 changes: 12 additions & 1 deletion packages/nextjs/utils/scaffold-eth/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,22 @@ export const RPC_CHAIN_NAMES: Record<number, string> = {
};

export const getAlchemyHttpUrl = (chainId: number) => {
return RPC_CHAIN_NAMES[chainId]
return scaffoldConfig.alchemyApiKey && RPC_CHAIN_NAMES[chainId]
? `https://${RPC_CHAIN_NAMES[chainId]}.g.alchemy.com/v2/${scaffoldConfig.alchemyApiKey}`
: undefined;
};

export const RPC_FALLBACKS: Record<number, string> = {
[chains.mainnet.id]: "https://eth.llamarpc.com",
[chains.arbitrum.id]: "https://arbitrum.llamarpc.com",
[chains.gnosis.id]: "https://gnosis.drpc.org",
[chains.sepolia.id]: "https://sepolia.gateway.tenderly.co",
};

export const getRpcFallbackUrl = (chainId: number) => {
return RPC_FALLBACKS[chainId];
};

export const NETWORKS_EXTRA_DATA: Record<string, ChainAttributes> = {
[chains.hardhat.id]: {
color: "#b8af0c",
Expand Down

0 comments on commit cdcd0da

Please sign in to comment.