I am developing a Dapp for the Binance Smart Chain and a issue appeared regarding setting up the metamask provider.

In ethereum, I'd set up the provider like that (using next.js):

import Web3 from "web3";
let web3;
if (typeof window !== "undefined" && typeof window.ethereum !== "undefined") {
  // We are in the browser and metamask is running.
  window.ethereum.request({ method: "eth_requestAccounts" });
  web3 = new Web3(window.ethereum);
} else {
  // We are on the server *OR* the user is not running metamask
  const provider = new Web3.providers.HttpProvider(
  web3 = new Web3(provider);
export default web3;

But that code will connect the browser web3 to the ethereum network using the client's provider.

What should I change this line for to connect to BSC instead?

web3 = new Web3(window.ethereum);


Browse other questions tagged or ask your own question.