简体   繁体   English

有什么方法可以向 Metamask 钱包发起断开请求?

[英]Is there any way to initiate a disconnect request to the Metamask wallet?

I'm building a decentralized application where users can connect their cryptocurrency wallet (Metamask) to my website.我正在构建一个去中心化应用程序,用户可以在其中将他们的加密货币钱包(Metamask)连接到我的网站。

They can initiate a connection request by clicking a button.他们可以通过单击按钮来发起连接请求。 On success, the wallet is connected and my website can interact with it.成功后,钱包已连接,我的网站可以与之交互。

Is there any way to initiate a disconnect request?有什么方法可以发起断开请求吗? Similar to a 'Log out' button.类似于“注销”按钮。 Currently, the users have to manually disconnect their wallet within Metamask settings which is not a straightforward process.目前,用户必须在 Metamask 设置中手动断开他们的钱包,这不是一个简单的过程。

Here is what I use to disconnect your connected account (assuming you have only one) from the application:这是我用来从应用程序断开连接的帐户(假设您只有一个)的方法:

await window.ethereum.request({
    method: "eth_requestAccounts",
    params: [{eth_accounts: {}}]
})

Not the answer you might be hoping for: It's not possible.不是您可能希望的答案:这是不可能的。

The connect/disconnect functionality is entirely in the user's hands due to security and privacy concerns.由于安全和隐私问题,连接/断开功能完全掌握在用户手中。 You can kindly ask the wallet to prompt the user to connect to the website, but there is no functionality to prompt the user to disconnect.您可以请钱包提示用户连接网站,但没有提示用户断开连接的功能。

Programmatically resetting the accounts array does not disconnect the wallet even though some implementations such as Pancake Swap suggest this is the case;以编程方式重置账户数组不会断开钱包,尽管 Pancake Swap 等一些实现表明这是这种情况; they simply pretend a disconnect.他们只是假装断开连接。

from this: https://github.com/MetaMask/metamask-extension/issues/8990从此: https://github.com/MetaMask/metamask-extension/issues/8990

 const accounts = await window.ethereum.request({ method: "wallet_requestPermissions", params: [{ eth_accounts: {} }] }).then(() => ethereum.request({ method: 'eth_requestAccounts' })) const account = accounts[0]

Credit to nikita: https://github.com/nikitamarcius归功于尼基塔:https://github.com/nikitamarcius

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 断开 dapp 与 MetaMask 的连接 - Disconnect dapp from MetaMask Web3:访问 MetaMask 钱包中的私钥 - Web3: accessing private key in MetaMask wallet 在 android 应用程序项目中连接到 metamask 钱包 - connecting to metamask wallet in android app project 将 eth 从一个 metamask 钱包稳定地发送到另一个钱包 - Sending eth from one metamask wallet to another wallet in solidity 如何在Unity的移动平台中连接metamask钱包? - How to connect metamask wallet in Mobile Platform of Unity? 如何在我的 MetaMask 钱包中正确获取不同代币的余额? - How to properly get the balance of different tokens in my MetaMask wallet? 每当我单击连接元掩码按钮时,为什么它会连接 coinbase 钱包? - Whenever i click on connect metamask button why it connects the coinbase wallet? 尝试将 MetaMask 钱包连接到 React - 如果用户单击 MetaMask 模态,该模态不会重新出现 - When attempting to connect MetaMask wallet to React - if user clicks out of the MetaMask modal, the modal doesn't reappear 交易在以太坊区块链浏览器上可见,但代币在 Metamask 钱包中不显示 - Transaction is visible on Ethereum blockchain explorer, but token is not displayed in Metamask wallet 如何在 React 的元掩码钱包中获取 BNB 代币余额? - How to get BNB token balance in metamask wallet in React?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM