赞
踩
yarn add web3
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('用户拒绝连接')
}
})
在vite-env.d.ts
文件中加入
declare interface Window{
ethereum:any
}
冒红消失
连接时报错
code :-32002
“Request of type ‘wallet_requestPermissions’ already pending for origin http://localhost:5173. Please wait.”
目前了解到的方法:需要手动进行点击插件进行管理钱包连接
取消后再申请
成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。