简体   繁体   中英

How to connect Metamask wallet address to web3 on bsc testnet on React

I am trying to connect my metamask wallet to the bsc testnet:

const web3 = new Web3('https://data-seed-prebsc-1-s1.binance.org:8545');

But when I try to get the accounts:

const accounts_ = await web3.eth.getAccounts()

web3.eth does not recognize the account on bsc testnet. Is there any configuration I am missing? Thanks!

Firstly connect web3 by requesting for connection by:

const accounts = await web3.eth.requestAccounts();

Then save the address:

const address = accounts[0];

Now to Add BNB network to your metask account, to do that follow these steps:

1: Open Metamask settings

2: Then open the Networks tab in the settings.

3: Then click on add networks button to open the network form.

4: Fill all the fields for Testnet BNB network as following

Hurray!! Now you have added the BNB network to your metamask.

Now refresh your page and click on the connect button on your page through which you call for the above functions for requesting address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM