当前位置:   article > 正文

Web3 Vue3连接MetaMask(小狐狸)钱包Request of type ‘wallet_requestPermissions‘ already pending for origin过程记录_小狐狸插件调用

小狐狸插件调用

下载web3依赖

yarn add web3
  • 1

连接申请

 window.ethereum.request({ method: 'eth_requestAccounts' }).then((res: any) => {
        console.log(res, '这就是小狐狸地址')
    }).catch((err: any) => {
        console.log('44',err)
        if (err.code===-32002) {
        // 用户在申请连接时既没有取消也没有同意钱包的绑定需要手动打开小狐狸钱包的插件进行绑定
        }
        if (err.code == 4001) {
            console.log('用户拒绝连接')
        }
    })
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

ethereum冒红

在这里插入图片描述
vite-env.d.ts文件中加入

declare interface Window{
    ethereum:any
}
  • 1
  • 2
  • 3

在这里插入图片描述
冒红消失

连接时报错
code :-32002
“Request of type ‘wallet_requestPermissions’ already pending for origin http://localhost:5173. Please wait.”
目前了解到的方法:需要手动进行点击插件进行管理钱包连接在这里插入图片描述
在这里插入图片描述
取消后再申请
在这里插入图片描述
成功

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/453516
推荐阅读
相关标签
  

闽ICP备14008679号