web3modal icon indicating copy to clipboard operation
web3modal copied to clipboard

Binance Smart Chain (BSC) Error!

Open ochikov opened this issue 4 years ago • 11 comments

Hello, I am trying to use walletConnect to connect to BSC. I am giving the params as:

 package: WalletConnectProvider,
        options: {
          rpc: {
            56: 'https://bsc-dataseed1.defibit.io/'
          },
          chainId: 56,
        }
      }

I am getting error:

index.ts:74 POST https://mainnet.infura.io/v3/ 401 Screenshot 2021-03-04 at 18 07 35

When adding the infuraId i am getting chainId 1 in provider network settings. Since I am using the provider to connect to a smart contracts in that network, I cannot connect because the chainId is wrong.

ochikov avatar Mar 04 '21 16:03 ochikov

Did you ever fix this?

assertdesignuk avatar Mar 26 '21 17:03 assertdesignuk

Try it:

const web3Modal = new Web3Modal({
    network: "binance", // replace mainnet to binance
    cacheProvider: true, // optional
    providerOptions, // required
});

phanthai12 avatar Apr 03 '21 16:04 phanthai12

Yes @assertdesignuk , I used:

providerOptions = {
        walletconnect: {
          package: WalletConnectProvider,
          options: {
            rpc: {
              56: 'https://bsc-dataseed.binance.org/'
            },
            network: 'binance',
            chainId: 56,
            infuraId: YOUR_INFURA_KEY,
          }
        }
      };

ochikov avatar Apr 04 '21 08:04 ochikov

@ochikov I just copied your code, but it not worked. Could you please tell me your WalletConnectProvider version and web3Modal version? Does these options work for BSC testnet?

Raincle avatar Apr 20 '21 13:04 Raincle

No, works only for mainnet. My provider is ethers.js web3provider

ochikov avatar May 11 '21 09:05 ochikov

Currently, I'm combing through the Infura documentation and I don't see that Binance is supported at the moment. Or am I missing a configuration somewhere that I can toggle Binance support?

djmbritt avatar May 12 '21 11:05 djmbritt

I'm also very curious about this. :)

danielmedvec avatar May 12 '21 12:05 danielmedvec

@djmbritt @danielmedvec I just set the provider options like this.

const providerOptions = {
  walletconnect: {
    package: WalletConnectProvider,
    options: {
      rpc: {
         56: 'https://bsc-dataseed.binance.org/'
      },
      network: 'binance',
    }
  }
};

and then

const web3Modal = new Web3Modal({
  cacheProvider: true, // optional
  providerOptions // required
});

const provider = await web3Modal.connect();
const web3 = new Web3(provider);

Make sure you are using the latest version of web3modal package.

atropos0902 avatar May 18 '21 08:05 atropos0902

thanks these posts have been very useful to me. I can't understand one thing though.

why use infuriaId if we can use bsc-dataseed.binance.org directly?

are there any differences? furthermore infuriaId is paid

ubuntutest avatar Jun 22 '21 11:06 ubuntutest

@djmbritt @danielmedvec I just set the provider options like this.

const providerOptions = {
  walletconnect: {
    package: WalletConnectProvider,
    options: {
      rpc: {
         56: 'https://bsc-dataseed.binance.org/'
      },
      network: 'binance',
    }
  }
};

and then

const web3Modal = new Web3Modal({
  cacheProvider: true, // optional
  providerOptions // required
});

const provider = await web3Modal.connect();
const web3 = new Web3(provider);

Make sure you are using the latest version of web3modal package.

i am trying to get it to work with both BSC and ETH Mainnet, is it possible?

On my site one page uses BSC and on the other ETH, how can I implement this system to make it work on both sides? or force a refresh in the page change?


    const providerOptions = {
        walletconnect: {
            package: WalletConnectProvider,
            options: {
                rpc: {
                    56: 'https://bsc-dataseed.binance.org/',
                    1: 'https://mainnet.infura.io/v3/',
                },
                infuraId: "INFURA_ID",
            }
        }
    };

GiacomoSilli avatar Jul 08 '21 22:07 GiacomoSilli

Anyone found how to add options to swap between ETH and BSC?

fegtomi avatar Aug 21 '21 18:08 fegtomi

With stable version 2.0.0 of Web3Modal now released, we are officially dropping support for version 1.x Due to this this issue/pr was marked for closing. It is highly recommended to upgrade as 2.x will be receiving further updates that will enable functionality for some of our newer sdks like auth and push as well as support for WalletConnect v2 (See this post about WalletConnect v1 being deprecated https://medium.com/walletconnect/walletconnect-v1-0-sunset-notice-and-migration-schedule-8af9d3720d2e)

If you need to continue using Web3Modal 1.x and require this feature/fix implemented, we suggest adding it via forking V1 branch.

xzilja avatar Jan 21 '23 14:01 xzilja