reactjs - 使用 web3 断开钱包与网站的连接
问题描述
我正在使用 web3 使用以下方法连接到元掩码
await window.ethereum.request({ method: 'eth_requestAccounts' });
var address = await window.ethereum.request({ method: 'eth_accounts' });
但是当我刷新屏幕时它仍然显示为已连接,我无法在 web3 中找到任何方法将其与 pancackswap 之类的网站断开连接
解决方案
据我所知,这是 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: {}
}
]
});
}
推荐阅读
- python - 在 Tkinter Python 中销毁一个窗口并打开另一个窗口
- dataframe - 在 pyspark 中创建数据框时,具有正确布尔值的记录会导致整行为空
- sql - 计数成对组合雪花
- pine-script - 根据价格收盘价高于或低于某些水平价格水平进行交易
- python - Python windows屏幕截图 - 连续流问题
- javascript - 如何在 pug 模板中使用 onClick 函数返回的值?
- c# - 在 WPF 中将自定义类与验证绑定
- database - 如何根据学生设计结果
- javascript - “获取文档时出错:FirebaseError:找不到匹配的索引。” -- 尝试在两个字段上使用 WHERE 子句
- android - 如何在 Android 中确定关闭 APK 的原因是什么?