首页 > 解决方案 > 使用 web3 断开钱包与网站的连接

问题描述

我正在使用 web3 使用以下方法连接到元掩码

await window.ethereum.request({ method: 'eth_requestAccounts' });
var address = await window.ethereum.request({ method: 'eth_accounts' });

但是当我刷新屏幕时它仍然显示为已连接,我无法在 web3 中找到任何方法将其与 pancackswap 之类的网站断开连接

标签: reactjsblockchainweb3metamask

解决方案


据我所知,这是 metamask 的一个持续未解决的问题,此解决方案只会断开第一个配置文件而不会弹出弹出窗口,将 isReturningUser 变量保存在本地存储中并相应地更新以控制功能逻辑流。

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

    if (!isReturningUser) {
    // Runs only they are brand new, or have hit the disconnect button
      await window.ethereum.request({
        method: "wallet_requestPermissions",
        params: [
          {
            eth_accounts: {}
          }
        ]
      });
    }

推荐阅读