In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what to do if you can't get the account of metamask". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
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 the privacy mode, or modify the JavaScript code to make it compatible with Metamask's 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:
Once the user clicks the connect button, your app can access the Metamask account as before.
This is the end of the content of "what to do if you can't get your metamask account". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.