Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to access the ethernet Fong account normally by Metamask

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to talk to you about how Metamask can normally access the Ethernet Square account. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something from this article.

When you use Metamask to test Ethernet Square DApp, if there is an inexplicable problem, check to see if web3.eth.accounts can get the account. If not, then the most likely reason is that you are using the new version of Metamask and the privacy mode is enabled by default.

There are two ways for your DApp to properly access an account managed by Metamask: turn off privacy mode, or modify the code to make it compatible with privacy mode.

First, turn off privacy mode

Enter the settings in metamask first, then click security & privacy. On the Privacy Mode menu, select disable Privacy Mode:

Second, compatible with privacy mode

When Metamask first introduced privacy mode in November 2018, this option was turned off by default. But in the latest version, privacy mode has been turned on by default. It is unrealistic to require each user to turn off privacy mode manually, so a better solution is to modify our JavaScript code to be compatible with privacy mode:

Window.addEventListener ('load', async ()) = > {/ / Modern dapp browsers... If (window.ethereum) {window.web3 = new Web3 (ethereum); try {/ / Request account access if needed await ethereum.enable (); / / Acccounts now exposed web3.eth.sendTransaction ({/ *... * /});} catch (error) {/ / User denied account access... }} / / Legacy dapp browsers... Else if (window.web3) {window.web3 = new Web3 (web3.currentProvider); / / Acccounts always exposed web3.eth.sendTransaction ({/ *... * /});} / / Non-dapp browsers... Else {console.log ('Non-Ethereum browser detected. You should consider trying MetaMaskies');}})

Use window.ethereum to determine whether the new metamask is new, and if so, call the ethereum.enable () method to request the user's authorization, which will pop up an authorization dialog in the user's web page, similar to the following:

After reading the above, do you have any further understanding of how Metamask can normally access the ethernet Fong account? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report