mirror of
https://github.com/luxfhe/example-redact.git
synced 2026-10-30 18:13:20 +00:00
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
"use client";
|
|
|
|
import { wagmiConnectors } from "./wagmiConnectors";
|
|
import { Chain, createClient, fallback, http } from "viem";
|
|
import { arbitrum, arbitrumSepolia, hardhat, mainnet, sepolia, baseSepolia } from "viem/chains";
|
|
import { createConfig } from "wagmi";
|
|
import deployedContracts from "~~/contracts/deployedContracts";
|
|
import scaffoldConfig, { DEFAULT_ALCHEMY_API_KEY } from "~~/scaffold.config";
|
|
import { getAlchemyHttpUrl } from "~~/utils/scaffold-eth";
|
|
|
|
const { targetNetworks } = scaffoldConfig;
|
|
|
|
// Define the multicall3 address for hardhat chain
|
|
const HARDHAT_MULTICALL3_ADDRESS = deployedContracts["31337"].Multicall3.address;
|
|
|
|
// We always want to have mainnet enabled (ENS resolution, ETH price, etc). But only once.
|
|
export const enabledChains = targetNetworks.find((network: Chain) => network.id === 1)
|
|
? targetNetworks
|
|
: ([...targetNetworks, sepolia, arbitrumSepolia, arbitrum, mainnet, baseSepolia] as const);
|
|
|
|
export const wagmiConfig = createConfig({
|
|
chains: enabledChains,
|
|
connectors: wagmiConnectors,
|
|
ssr: true,
|
|
client({ chain }) {
|
|
let rpcFallbacks = [http()];
|
|
|
|
const alchemyHttpUrl = getAlchemyHttpUrl(chain.id);
|
|
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:
|
|
chain.id === hardhat.id
|
|
? // Add multicall3 contract address to hardhat chain
|
|
{
|
|
...chain,
|
|
contracts: {
|
|
...chain.contracts,
|
|
multicall3: {
|
|
address: HARDHAT_MULTICALL3_ADDRESS,
|
|
},
|
|
},
|
|
}
|
|
: chain,
|
|
transport: fallback(rpcFallbacks),
|
|
...(chain.id !== (hardhat as Chain).id
|
|
? {
|
|
pollingInterval: scaffoldConfig.pollingInterval,
|
|
}
|
|
: {}),
|
|
});
|
|
},
|
|
});
|