-1

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

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

1

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: {}
  }
])}
xitalianx
  • 23
  • 3