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

Here is a passing phase guide on how to connect the Metamark portfolio to BSC Testnet using web3.js and react:

Premise

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

  • Install Metamark and Web3.js`'

  • Configure the Waller Metask on the test (BSC)

  • Create a new React Project:NPX Create-Corect-App Metask Testnet

Step 1: BSC TESTNET ENTRY IN METAMANS

  • Open the metamark wallet and sail on
    settings

  • Access
    Advanced settings >
    Network

  • Select
    Test Binance Smart Chain (BSC) from the available networks

  • Make sure the testnet network is enabled

Step 2: configure web3.js on the React project

1

2

`Javascript

Import * as web3 from “web3”;

consist supplier = new web3.providers.httpprovider (‘ prembsc.11.binance.org:8545’);

`

Step 3: Connect the metamark portfolio to web3.js

Create a new file called MetamarkConnect.js and add the following code:

`Javascript

Import * as web3 from “web3”;

Import {MetamarkConnect} from ‘./metamark-connector’;

Const conts_ = waiting for MetamarkConnect ();

`

This will connect the Metask portfolio to the testnet network using the Metask-Connector.js.

Step 4: Configure your account to find

Create a new file called cont.js and add the following code:

`Javascript

Import * as web3 from “web3”;

Import {conts_} from ‘./metamarkconnect’;

consists account = Wait Web3.etth.eTaccoTots ();

Console.log (account);

`

This will take control of the addresses of the Metask Waller connected to the account testnet.

Step 5: use accounts in the application of your react

Update the app.js to use the accounts taken:

`Javascript

Import * I would react, {Usestate} from ‘react’;

import web3 from ‘./web3’;

Function App () {

Const [Account, SetacounTS] = Usestate (conts_);

Return (

Metamams Testin account

    {Cont.Map ((Cont) => (

  • {account}
  • ))}

);

}

MetatasktestNet () {

Return (

!

{/ Content of the REACT application here /}

);

}

`

This will display the addresses of the Waller Metask connected to the account testnet in a list.

That’s all! Now you should be able to connect the Metask portfolio to BSC Testnet and recover accounts using web3.js.

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *