From 42e16e82628a77cb46c9b373d8d7cc3edc2bfc37 Mon Sep 17 00:00:00 2001 From: Afrijal Dzuhri Date: Tue, 17 Nov 2026 18:15:16 +0700 Subject: [PATCH] fix: repair the Sepolia add-network request and replace the dead RPC When the wallet does not know Sepolia, wallet_switchEthereumChain returns 4902 and the client falls back to wallet_addEthereumChain. That call failed in both places that use it. The wrong-network prompt in App.js sent a malformed parameter that only held a nested chainId, so wallets rejected it. It now sends the same fields as Header.js, read from NETWORKS_INGAME.SEPOLIA. The Sepolia rpcUrl pointed to rpc.sepolia.org, which no longer responds, so wallets refused to add the network from the dropdown too. It now points to the publicnode Sepolia endpoint. --- client/src/constants.js | 2 +- client/src/containers/App.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/client/src/constants.js b/client/src/constants.js index 24ccaccbb..477cae031 100644 --- a/client/src/constants.js +++ b/client/src/constants.js @@ -62,7 +62,7 @@ export const NETWORKS_INGAME = { id: "11155111", currencyName: "Sepolia-ETH", currencySymbol: "SEP", - rpcUrl: `https://rpc.sepolia.org`, + rpcUrl: `https://ethereum-sepolia-rpc.publicnode.com`, blockExplorer: "https://sepolia.etherscan.io", explorer: { apiKey: `${process.env.REACT_APP_SEPOLIA_EXPLORER_API_KEY}`, diff --git a/client/src/containers/App.js b/client/src/containers/App.js index fcc48a350..9a11c4272 100644 --- a/client/src/containers/App.js +++ b/client/src/containers/App.js @@ -116,18 +116,21 @@ class App extends React.Component { } catch (switchError) { // This error code indicates that the chain has not been added to MetaMask. if (switchError.code === 4902) { + const sepolia = constants.NETWORKS_INGAME.SEPOLIA; try { await window.ethereum.request({ method: "wallet_addEthereumChain", params: [ { - chainId: [ - { - chainId: `0x${Number( - constants.NETWORKS.SEPOLIA.id - ).toString(16)}`, - }, - ], + chainId: `0x${Number(sepolia.id).toString(16)}`, + chainName: sepolia.name, + rpcUrls: [sepolia.rpcUrl], + nativeCurrency: { + name: sepolia.currencyName, + symbol: sepolia.currencySymbol, + decimals: 18, + }, + blockExplorerUrls: [sepolia.blockExplorer], }, ], });