Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
How to check if a web3 wallet is unlocked?

What is the best practice to see if metamask or other web3 wallets are unlocked with ethers.js?

I currently use this:

window.ethereum._metamask.isUnlocked()

But it is reported as experimental methods by the metamask documentation and I would like to find something better.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

What my experimentation found was that listAccounts returns an array of strings and if the wallet is not unlocked, it returns an empty array.

For MetaMask specifically, I know you can't have an account without having an address.

Therefore the function I came up with was:

async function isUnlocked() {
    const provider = new ethers.providers.Web3Provider(window.ethereum);

    let unlocked;

    try {
        const accounts = await provider.listAccounts();

        unlocked = accounts.length > 0;
    } catch (e) {
        unlocked = false;
    }

    return unlocked;
}
about 4 years ago · Juan Pablo Isaza Report

0

That's my own resolution if anyone need it :

isUnlocked$ = new BehaviorSubject<boolean>(false);

async isWalletUnlocked() {
      const web3Provider = new ethers.providers.Web3Provider(window.ethereum, 'any');
      const signer = await this.web3Provider.getSigner();
    
      signer
      .getAddress()
      .then((address: string) => {
        this.isUnlocked$.next(true);
      })
      .catch((err) => this.isUnlocked$.next(false));
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!