Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/eight-pears-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"create-eth": patch
---

- feat: lazy load wallet connectors to prevent ssr errors (https://github.com/scaffold-eth/scaffold-eth-2/pull/1163)
- up wagmi viem and rainbow version (https://github.com/scaffold-eth/scaffold-eth-2/pull/1172)
- fix bg rpc url (https://github.com/scaffold-eth/scaffold-eth-2/pull/1174)
- update Celo Testnet from Celo Alfajores to Celo Sepolia (https://github.com/scaffold-eth/scaffold-eth-2/pull/1171)
- docs: add production usage warning for `useScaffoldEventHistory` (https://github.com/scaffold-eth/scaffold-eth-2/pull/1173)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import { useInfiniteQuery, useQuery } from "@tanstack/react-query";
import { Abi, AbiEvent, ExtractAbiEventNames } from "abitype";
import { BlockNumber, GetLogsParameters } from "viem";
import { hardhat } from "viem/chains";
import { Config, UsePublicClientReturnType, useBlockNumber, usePublicClient } from "wagmi";
import { useSelectedNetwork } from "~~/hooks/scaffold-eth";
import { useDeployedContractInfo } from "~~/hooks/scaffold-eth";
Expand Down Expand Up @@ -54,7 +55,11 @@ const getEvents = async (
};

/**
* Reads events from a deployed contract
* @deprecated **Recommended only for local (hardhat/anvil) chains and development.**
* It uses getLogs which can overload RPC endpoints (especially on L2s with short block times).
* For production, use an indexer such as ponder.sh or similar to query contract events efficiently.
*
* Reads events from a deployed contract.
* @param config - The config settings
* @param config.contractName - deployed contract name
* @param config.eventName - name of the event to listen for
Expand Down Expand Up @@ -91,6 +96,15 @@ export const useScaffoldEventHistory = <
}: UseScaffoldEventHistoryConfig<TContractName, TEventName, TBlockData, TTransactionData, TReceiptData>) => {
const selectedNetwork = useSelectedNetwork(chainId);

// Runtime warning for non-local chains
useEffect(() => {
if (selectedNetwork.id !== hardhat.id) {
console.log(
"⚠️ useScaffoldEventHistory is not optimized for production use. It can overload RPC endpoints (especially on L2s)",
);
}
}, [selectedNetwork.id]);

const publicClient = usePublicClient({
chainId: selectedNetwork.id,
});
Expand Down
8 changes: 4 additions & 4 deletions templates/base/packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
},
"dependencies": {
"@heroicons/react": "~2.1.5",
"@rainbow-me/rainbowkit": "2.2.7",
"@rainbow-me/rainbowkit": "2.2.8",
"@tanstack/react-query": "~5.59.15",
"@uniswap/sdk-core": "~5.8.2",
"@uniswap/v2-sdk": "~4.6.1",
"blo": "~1.2.0",
"burner-connector": "0.0.16",
"burner-connector": "0.0.18",
"daisyui": "5.0.9",
"kubo-rpc-client": "~5.0.2",
"next": "~15.2.3",
Expand All @@ -33,8 +33,8 @@
"react-dom": "~19.0.0",
"react-hot-toast": "~2.4.0",
"usehooks-ts": "~3.1.0",
"viem": "2.31.1",
"wagmi": "2.15.6",
"viem": "2.34.0",
"wagmi": "2.16.4",
"zustand": "~5.0.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const scaffoldConfig = ${stringify(finalConfig, {
alchemyApiKey: "This is ours Alchemy's default API key.\nYou can get your own at https://dashboard.alchemyapi.io\nIt's recommended to store it in an env variable:\n.env.local for local testing, and in the Vercel/system env config for live apps.",
walletConnectProjectId: "This is ours WalletConnect's default project ID.\nYou can get your own at https://cloud.walletconnect.com\nIt's recommended to store it in an env variable:\n.env.local for local testing, and in the Vercel/system env config for live apps.",
rpcOverrides: "If you want to use a different RPC for a specific network, you can add it here.\nThe key is the chain ID, and the value is the HTTP RPC URL",
"rpcOverrides.": "Example:\n[chains.mainnet.id]: \"https://mainnet.buidlguidl.com\",",
"rpcOverrides.": "Example:\n[chains.mainnet.id]: \"https://mainnet.rpc.buidlguidl.com\",",
})} as const satisfies ScaffoldConfig;

export default scaffoldConfig;`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { deepMerge, withDefaults, stringify } from "../../../../../utils.js";

const defaultWagmiConfig = {
chains: '$$enabledChains$$',
connectors: '$$wagmiConnectors$$',
connectors: '$$wagmiConnectors()$$',
ssr: true,
client: `$$({ chain }) => { let rpcFallbacks = [http()]; const rpcOverrideUrl = (scaffoldConfig.rpcOverrides as ScaffoldConfig["rpcOverrides"])?.[chain.id]; if (rpcOverrideUrl) { rpcFallbacks = [http(rpcOverrideUrl), http()]; } else { const alchemyHttpUrl = getAlchemyHttpUrl(chain.id); if (alchemyHttpUrl) { const isUsingDefaultKey = scaffoldConfig.alchemyApiKey === DEFAULT_ALCHEMY_API_KEY; rpcFallbacks = isUsingDefaultKey ? [http(), http(alchemyHttpUrl)] : [http(alchemyHttpUrl), http()]; } } return createClient({ chain, transport: fallback(rpcFallbacks), ...(chain.id !== (hardhat as Chain).id ? { pollingInterval: scaffoldConfig.pollingInterval, } : {}), }); }$$`,
}
Expand Down
30 changes: 19 additions & 11 deletions templates/base/packages/nextjs/services/web3/wagmiConnectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,24 @@ const wallets = [
/**
* wagmi connectors for the wagmi context
*/
export const wagmiConnectors = connectorsForWallets(
[
export const wagmiConnectors = () => {
// Only create connectors on client-side to avoid SSR issues
// TODO: update when https://github.com/rainbow-me/rainbowkit/issues/2476 is resolved
if (typeof window === "undefined") {
return [];
}

return connectorsForWallets(
[
{
groupName: "Supported Wallets",
wallets,
},
],

{
groupName: "Supported Wallets",
wallets,
appName: "scaffold-eth-2",
projectId: scaffoldConfig.walletConnectProjectId,
},
],

{
appName: "scaffold-eth-2",
projectId: scaffoldConfig.walletConnectProjectId,
},
);
);
};
4 changes: 2 additions & 2 deletions templates/base/packages/nextjs/utils/scaffold-eth/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const RPC_CHAIN_NAMES: Record<number, string> = {
[chains.baseGoerli.id]: "base-goerli",
[chains.baseSepolia.id]: "base-sepolia",
[chains.celo.id]: "celo-mainnet",
[chains.celoAlfajores.id]: "celo-alfajores",
[chains.celoSepolia.id]: "celo-sepolia",
};

export const getAlchemyHttpUrl = (chainId: number) => {
Expand Down Expand Up @@ -87,7 +87,7 @@ export const NETWORKS_EXTRA_DATA: Record<string, ChainAttributes> = {
[chains.celo.id]: {
color: "#FCFF52",
},
[chains.celoAlfajores.id]: {
[chains.celoSepolia.id]: {
color: "#476520",
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ const defaultConfig = {
url: "https://forno.celo.org",
accounts: ["$$deployerPrivateKey$$"],
},
celoAlfajores: {
url: "https://alfajores-forno.celo-testnet.org",
celoSepolia: {
url: "https://forno.celo-sepolia.celo-testnet.org/",
accounts: ["$$deployerPrivateKey$$"],
},
},
Expand Down