Why does Brave browser try to connect to localhost:8545 instead of the Ethereum mainnet?

My web3 application is live on the ethereum mainnet, with no problems from Chrome using the metamask extension. It also works fine using Brave Browser’s native wallet while testing on the goerli testnet. But on the mainnet, Brave throws the error:

Failed to load resource: net::ERR_CONNECTION_REFUSED Uncaught (in promise) Error: CONNECTION ERROR: Couldn’t connect to node http://localhost:8545.

The expected behavior is for the Brave wallet to connect to the Ethereum mainnet, not a local network. As mentioned, it works as expected on the goerli testnet and on the mainnet with Chrome.

Here is the file where the connection is made:

import Web3 from 'web3';

let web3;

if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined') {
  // client side
  try {
    web3 = new Web3(window.ethereum);
    // window.ethereum.enable(); // deprecated
    window.ethereum.request({ method: 'eth_requestAccounts' });
  } catch(error) {
    console.log(error);
  }
} else {
  // server side
  try {
    const provider = new Web3.providers.HttpProvider(process.env.INFURA_NODE);
    web3 = new Web3(provider);
  } catch(error) {
    console.log(error);
  }
}

export default web3;

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.