Skip to content

Conversation

@mxber2022
Copy link

Issue Summary

Problem: FHEVM React app was failing to load with RelayerSDKLoader: window does not contain 'relayerSDK' property and POST http://127.0.0.1:8545/ net::ERR_CONNECTION_REFUSED errors when developing on Sepolia network.

Root Cause: The application was configured to use Hardhat (localhost:8545) as the default target network, causing all RPC requests to go to localhost even when the wallet was connected to Sepolia. This happened because:

  1. The useDeployedContractInfo hook runs before wallet connection is established
  2. It falls back to the default targetNetwork from the Zustand store
  3. The default was set to Hardhat (first network in targetNetworks array)
  4. This caused wagmi to create RPC clients pointing to localhost:8545
  5. No local Hardhat node was running, resulting in connection refused errors

Solution

Fix: Changed the default target network from Hardhat to Sepolia in the Zustand store configuration.

Files Modified:

  1. packages/nextjs/services/store/store.ts

    // Before
    targetNetwork: {
      ...scaffoldConfig.targetNetworks[0], // Hardhat
      ...NETWORKS_EXTRA_DATA[scaffoldConfig.targetNetworks[0].id],
    },
    
    // After  
    targetNetwork: {
      ...scaffoldConfig.targetNetworks[1], // Sepolia
      ...NETWORKS_EXTRA_DATA[scaffoldConfig.targetNetworks[1].id],
    },
  2. packages/nextjs/app/_components/FHECounterDemo.tsx

    • Made initialMockChains configuration dynamic based on current chain ID
    • Added debugging logs for better troubleshooting
    • Ensured FHEVM SDK uses correct RPC endpoint for each network

Result:

  • ✅ Eliminated all localhost:8545 connection errors
  • ✅ FHEVM SDK now loads and initializes correctly
  • ✅ Application works out-of-the-box on Sepolia without requiring local Hardhat node
  • ✅ Still supports localhost development when wallet is connected to Hardhat

This fix ensures the application works seamlessly for Sepolia development while maintaining compatibility with localhost development when needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant