[英]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.