注销元掩码用户单击按钮如何实现?

问题描述 投票:0回答:1

我正在开发一个 dapp,我已经使用 ether js 实现了签名选项,但我还想在单击按钮时调用一个函数来注销连接的元掩码钱包。之前我使用过 Moralis v1 注销功能,但在这个版本中没有注销选项。我该怎么做?

我正在使用 Next.js、Ether js 和 Moralis

next.js blockchain web3js decentralized-applications moralis
1个回答
1
投票

使用 ether.js,您可以使用以下功能管理登录和注销:

async function login() {
const ethers = require('ethers');
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const walletAddress = await signer.getAddress(); //get user address
}


async function logout() {
const ethers = require('ethers');
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
await signer.provider.send('wallet_requestPermissions', [
  {
    eth_accounts: {}
  }
])}
© www.soinside.com 2019 - 2024. All rights reserved.