logout metamask user onClick a button how can I implement it?

208 views Asked by At

I am working on a dapp and I have implemented signing option using ether js but I want to also call a fucntion onclick a button to logout connected metamask wallet. Before I have used Moralis v1 logout fucntion but in this version there is no option to logout. How can i do this?

I am using Next.js, Ether js, and Moralis

1

There are 1 answers

0
xitalianx On

Using ether.js you can manage login and logout using these functions:

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: {}
  }
])}