使用 web3 从网站断开钱包

Roh*_*rya 6 reactjs blockchain web3js metamask

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

await window.ethereum.request({ method: 'eth_requestAccounts' });
var address = await window.ethereum.request({ method: 'eth_accounts' });
Run Code Online (Sandbox Code Playgroud)

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

Ore*_*ico 1

据我所知,这是一个持续存在的元掩码问题,此解决方案只会断开第一个配置文件而不弹出窗口,将 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: {}
          }
        ]
      });
    }
Run Code Online (Sandbox Code Playgroud)